charlycou
charlycou

Reputation: 1998

cross-env not setting NODE_ENV

I want to set environment variables to configure URL at runtime. I use webpack to bundle the js and here is the plugin defined to make the NODE_ENV available during compile time.

new webpack.DefinePlugin({
  'process.env':{
    'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
    //'TARGET_ENV': JSON.stringify(process.env.TARGET_ENV)
  }
})

Here are the yarn I want to execute according to the targeted environment:

"test-kubernetes": "cross-env NODE_ENV=kubernetes-cluster webpack && yarn run testenv",
"build": "cross-env NODE_ENV=production webpack --mode=production",
"dev": "cross-env NODE_ENV=development webpack --mode=development && webpack-dev-server --hot",

However process.env.NODE_ENV is undefined at runtime. This issue seems to be related to cross-env since using:

SET NODE_ENV=kubernetes-cluster

instead of

cross-env NODE_ENV=kubernetes-cluster

on my Windows machine makes things work.

Any idea?

Upvotes: 2

Views: 4855

Answers (1)

charlycou
charlycou

Reputation: 1998

There is a regression since 5.2.0 for Windows environment. I managed to make things work switching back to 5.1.6. Reference issue: https://github.com/kentcdodds/cross-env/issues/185

Upvotes: 3

Related Questions