Skip to content

Module not found: Can't resolve 'react' #2534

Closed
@p-adams

Description

@p-adams

I am currently facing this problem when I attempt to install any node package into an app created with create-react-app:

`npm WARN gentlyRm not removing /Users/user/Desktop/mobx-shopping/node_modules/espree/node_modules/.bin/acorn as it wasn't installed by /Users/user/Desktop/mobx-shopping/node_modules/espree/node_modules/acorn
npm notice created a lockfile as package-lock.json. You should commit this file.

npm WARN mobx-react@4.2.1 requires a peer of react@^0.13.0 || ^0.14.0 || ^15.0.0 || ^16.0.0-0 but none was installed.`

Then when I run the app with npm start and it compiles, I get the following error:

 Failed to compile.
 ./src/index.js
 Module not found: Can't resolve 'react' in '/Users/user/Desktop/mobx-shopping/src'

Node version: 8.0.0
NPM version: 5.0.3
React: 15.6.0

Activity

gaearon

gaearon commented on Jun 14, 2017

@gaearon
Contributor

Try removing package-lock.json, run npm install and then npm start again. Please also share your package.json file.

If it doesn't help, install an older version of npm (e.g. 3.x). 5.x is still fairly buggy and might be causing this.

I'll close because it is not an issue on our side. npm just failed to install the react module for some reason.

maciej-gurban

maciej-gurban commented on Jun 15, 2017

@maciej-gurban

Removing package-lock.json and then running npm install helped me, thanks!

tridungbk2010

tridungbk2010 commented on Aug 23, 2017

@tridungbk2010

it worked fine for me:

{
            test: /\.scss$/,
            use: [
              require.resolve('style-loader'),
              {
                loader: "style-loader"
              }, {
                loader: "css-loader"
              }, {
                loader: "sass-loader",
                options: {
                  includePaths: ["absolute/path/a", "absolute/path/b"]
                }
              },
              {
                loader: require.resolve('postcss-loader'),
                options: {
                  // Necessary for external CSS imports to work
                  // https://github.com/facebookincubator/create-react-app/issues/2677
                  ident: 'postcss',
                  plugins: () => [
                    require('postcss-flexbugs-fixes'),
                    autoprefixer({
                      browsers: [
                        '>1%',
                        'last 4 versions',
                        'Firefox ESR',
                        'not ie < 9', // React doesn't support IE8 anyway
                      ],
                      flexbox: 'no-2009',
                    }),
                  ],
                },
              },
            ],
          }
Udosaint

Udosaint commented on Oct 15, 2017

@Udosaint

it did not help me after removing package-lock.json i run npm install and it still install another package-lock.json and the error still remains

flq

flq commented on Oct 31, 2017

@flq

Same here - the error location changed, but it couldn't find react nonetheless. Incredibly weird.

gaearon

gaearon commented on Oct 31, 2017

@gaearon
Contributor

Delete package-lock.json and yarn.lock.
Check if node_modules/react exists.
If it doesn't, check if react is in your package.json. If you don't have it in package.json, add it.

Run npm install (or yarn if you use it).
Check if node_modules/react exists.

If it doesn't, something's messed up with npm or Yarn on your system. Try to update either.
If that doesn't help, file a bug with them.

If you have node_modules/react but CRA app can't resolve it, please file a new issue with us.

locked and limited conversation to collaborators on Oct 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @flq@gaearon@tridungbk2010@maciej-gurban@p-adams

        Issue actions

          Module not found: Can't resolve 'react' · Issue #2534 · facebook/create-react-app