question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"npm test" does not work with react-scripts@2.0 + react-app-rewired

See original GitHub issue

npm test throws errors in brand new CRA2.0 app (https://github.com/facebook/create-react-app/issues/3815)

Steps to reproduce

1) Create CRA@2.0 app with react-app-rewired

cd /tmp
npx create-react-app@next --scripts-version=2.0.0-next.66cc7a90 my-react-app
cd my-react-app
npm install
npm install react-app-rewired --save-dev

2) Create a config-overrides.js file in the root directory

/* config-overrides.js */

module.exports = function override(config, env) {
  //do stuff with the webpack config...
  return config;
}

3) ‘Flip’ the existing calls to react-scripts in npm scripts

  /* package.json */

  "scripts": {
-   "start": "react-scripts start",
+   "start": "react-app-rewired start",
-   "build": "react-scripts build",
+   "build": "react-app-rewired build",
-   "test": "react-scripts test --env=jsdom",
+   "test": "react-app-rewired test --env=jsdom"
}

4) Run npm test

Expected

test ran successfully

Current behaviour

> my-react-app@0.1.0 test /private/tmp/my-react-app
> react-app-rewired test --env=jsdom

/private/tmp/my-react-app/node_modules/react-scripts/scripts/utils/createJestConfig.js:35
    roots: srcRoots.map(toRelRootDir),
                    ^

TypeError: srcRoots.map is not a function
    at module.exports (/private/tmp/my-react-app/node_modules/react-scripts/scripts/utils/createJestConfig.js:35:21)
    at Object.<anonymous> (/private/tmp/my-react-app/node_modules/react-app-rewired/scripts/test.js:16:16)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)
    at Function.Module.runMain (module.js:703:10)
    at startup (bootstrap_node.js:193:16)
    at bootstrap_node.js:660:3
npm ERR! Test failed.  See above for more details.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
sowhatdoidocommented, Sep 12, 2018

I tried installing react-app-rewired ^1.6.2 and react-scripts 2.0.0-next.a671462c, then manually performing the update found in #243, and everything seems to work fine

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-app-rewired - npm
It is not able to configure compilation in test mode because test mode does not get run through Webpack at all (it runs...
Read more >
85 - Stack Overflow
I encountered this problem after I did an npm update. These packages were installed: "react-leaflet": "^3.2.0".
Read more >
How To Set Up a React Project with Create React App
Node.js version 10.16.0 installed on your computer. To install this on macOS ... Like npm test , this script does not need the...
Read more >
react-app-rewired-esbuild - npm package - Snyk
The npm package react-app-rewired-esbuild was scanned for known vulnerabilities and missing license, and no issues were found. Thus the package was deemed as ......
Read more >
How to polyfill node core modules in webpack 5 - Alchemy
Because the current version of webpack no longer includes NodeJS polyfills by default, it is causing issues for developers that use create-react ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found