#SyntaxError on passing `define` argument while compiling

1 messages · Page 1 of 1 (latest)

vivid sand
#
PS F:\REPO> bun build --define process.env.NODE_ENV=development  src/index.ts --minify --compile --target=bun-windows-x64 --sourcemap --outfile dist/targets/bin
 [112ms]  minify  -1.66 MB (estimate)
  [49ms]  bundle  483 modules
SyntaxError: An error occurred while parsing code
#

Not so much info is provided as in docs --define is supported

ornate lintel
#

maybe you can try setting NODE_ENV outside the build command?

NODE_ENV=production bun build src/index.ts --minify --compile --target=bun-windows-x64 --sourcemap --outfile dist/targets/bin
#

actually for powershell it would be $Env:NODE_ENV = 'production' instead of NODE_ENV=production

strange dune
#

The value passed to the define flag are “literally” replaced, so in your case with the command you provided if (process.env.NODE_ENV === 'development') {…} will be if (development === ‘development') {…} but here the variable development does not exist

#

You need to use quotes

vivid sand
#

I was trying something new, i wrote a script to bundle this and found that process.env does not get replaced, i think this is because of double quotes.

#

process.env

#

Explicitly write a undeclared variable

#

in index.js the node_env value is defined as a variable but the other env variable is written the same way without double quotes i tried the other way adding "development" in .env and does not works

#

But in counterpart of my first image, defining Bun.env does replace