I'm encountering an issue while trying to access process.env.NODE_ENV
within my application. Whenever I check it, I only receive the error message process is not defined
.
package.json
:
"scripts": {
"dev": "node ./node_modules/webpack/bin/webpack.js",
"prod": "NODE_ENV=production node ./node_modules/webpack/bin/webpack.js -p"
},
webpack.config.js
:
const NODE_ENV = process.env.NODE_ENV ? process.env.NODE_ENV.toLowerCase() : 'development';
and below :
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(NODE_ENV),
'URL_DEV': JSON.stringify("specificIP"),
'URL_PROD': JSON.stringify("OtherIP")
}
})
]
Within the source code of the app:
switch (process.env.NODE_ENV) {
case 'development':
url = process.env.URL_DEV;
break;
case 'production':
url = process.env.URL_PROD;
break;
default:
url = process.env.URL_DEV;
}
Despite implementing these changes, I am still facing the issue with process
being undefined. Can anyone point out what mistake I might be making in this setup?