Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Next Steps with Create React App

benjaminmosery
benjaminmosery
6,346 Points

Cannot find module 'react' from 'Accordion.js'

After running my searchapp, accessing the searchapp command directory using "cd searchapp", and running a test module using "npm test", I get the following error:

> react-scripts test --env=jsdom
 FAIL  src\App.test.js
  ● Test suite failed to run

    Cannot find module 'react' from 'Accordion.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
      at Object.<anonymous> (../node_modules/react-bootstrap/lib/Accordion.js:21:14)

My App.test.js file is as follows, for clarification:

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';


it('renders without crashing', () => {
  const div = document.createElement('div');
  ReactDOM.render(<App />, div);
  ReactDOM.unmountComponentAtNode(div);
});

Why is the test not passing in Node's npm command prompt? Any help would be appreciated.

1 Answer

benjaminmosery
benjaminmosery
6,346 Points

I have react as a dependency in the package.json file:

{
  "name": "searchapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-scripts": "1.1.1"
  },

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}
Gustavo Winter
Gustavo Winter
Courses Plus Student 27,382 Points

Try to delete your node_modules folder, and install all the packages again.

You will have to do the npm command at the main directory.

npm install

Tell me if the problem was solve