0

I'm using reactstrap@8.6.0 with nx and typescript. But if any component is included from reactstrap the app is crashing with below error

index.js:3 Uncaught ReferenceError: global is not defined
    at Object.../../../node_modules/has-symbols/index.js (index.js:3)
    at __webpack_require__ (bootstrap:79)
    at Object.../../../node_modules/get-intrinsic/index.js (index.js:54)
    at __webpack_require__ (bootstrap:79)
    at Object.../../../node_modules/call-bind/callBound.js (callBound.js:3)
    at __webpack_require__ (bootstrap:79)
    at Object.../../../node_modules/is-arguments/index.js (index.js:4)
    at __webpack_require__ (bootstrap:79)
    at Object.../../../node_modules/deep-equal/index.js (index.js:2)
    at __webpack_require__ (bootstrap:79)

As suggested here tried below configuration in jest.config.js but avail no luck.

module.exports = {
  name: 'cadence',
  preset: '../../jest.config.js',
  transform: {
    '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest',
    '^.+\\.[tj]sx?$': [
      'babel-jest',
      { cwd: __dirname, configFile: './babel-jest.config.json' },
    ],
  },
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
  coverageDirectory: '../../coverage/apps/cadence',
  setupFilesAfterEnv: ['./jest.setup.js'],
  target: 'node',
  node: { global: true },
};

Any help will be really appreciated.

Ravi MCA
  • 2,491
  • 4
  • 20
  • 30
  • 1
    Tried placing `` in `index.html` as suggested [here](https://stackoverflow.com/questions/65586906/react-and-electron-with-draft-js-global-is-not-defined#answer-67336441) and it worked – Ravi MCA Dec 22 '21 at 13:32

1 Answers1

0

I had a similar issue and solved by modifying webpack config - Add webpack.config.js to apps/your-react-app/webpack.config.js with:

const nrwlConfig = require('@nrwl/react/plugins/webpack.js');

module.exports = (config, context) => {
    nrwlConfig(config);

    return {
        ...config,
        node: {
            global: true,
        },
    };
};
zemil
  • 3,235
  • 2
  • 24
  • 33