metalsmith / metalsmith/js-bundle

Fix: don't crash the build if env var passed to define is undefined

Open
#6 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1
Forks
2
PR merge metrics
No merged PRs in 30d

Description

When a ms build is run like so

```js
metalsmith
.env('NODE_ENV', undefined)
.use(jsBundle())
```
esbuild throws an error, halting the MS build
```
▲ [WARNING] "process.env.NODE_ENV" is defined as an identifier instead of a string (surround "undefined" with quotes to get a string) [suspicious-define]

:1:34:
1 │ define: { 'process.env.NODE_ENV': 'undefined' }
│ ~~~~~~~~~~~
╵ '"undefined"'
```
This may be desirable when the `define` option is explicitly set, but is definitely unexpected when it's not. Solution is to replace the undefined value with the string undefined.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing how the Metalsmith .env value reaches the esbuild define configuration when jsBundle() runs. Reproduce the undefined-value build, then verify that it completes without the suspicious-define error and that explicitly supplied define values still behave as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.