1

Per research I've read that for cross platforms setting NODE_ENV is done better with cross-env after reading:

after I've tried to use set and export in the package.json scripts but I still receive an 'undefined'. The combinations I've tried to set my NODE_ENV are:

attempt 1 after research:

"devDependencies": {
  "cross-env": "^7.0.2"
}

"scripts": {
  "dev-server": "cross-env NODE_ENV=development webpack-dev-server",
}

attempt 2 from reading comments and answers:

"scripts": {
  "dev-server": "set NODE_ENV=development&& webpack-dev-server",
}

with:

"scripts": {
  "dev-server": "set NODE_ENV=development && webpack-dev-server",
}

and:

"scripts": {
  "dev-server": "export NODE_ENV=development && webpack-dev-server",
}

but in my Redux store I continue to get undefined:

configureStore.js:

import { createStore, combineReducers } from "redux";
  import fooReducer from "../reducers/foo";
  import barReducer from "../reducers/bar";
  
  const inDev =
    process.env.NODE_ENV === "development"
      ? window.__REDUX_DEVTOOLS_EXTENSION__ &&
        window.__REDUX_DEVTOOLS_EXTENSION__()
      : "";
  
  export default () => {
    console.log(process.env.NODE_ENV);
  
    const store = createStore(
      combineReducers({
        foo: fooReducer,
        bar: barReducer,
      }),
      inDev
    );
  
    return store;
  };

terminal command I use is in VSC:

yarn run dev-server

The app works but a console log shows undefined and if the ternary is modified to process.env.NODE_ENV === undefined the extension works. Other Q&As I've read:

Currently the app works but for some reason I cannot set process.env.NODE_ENV in package.json and the plugin tells me "No Store found" which is accurate because the NODE_ENV is undefined. How can I define within the script dev-server as a NODE_ENV=development in package.json?

DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127

0 Answers0