Skip to content

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

Description

@webketje

When a ms build is run like so

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]

    <js>: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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions