Skip to content

Module not found: Can't resolve './node_modules/react' #9098

Closed
@0xBradock

Description

@0xBradock

Hello,

I'm going crazy with this issue.
I tried everything I can find, but the suggestions do not work.

Thanks for helping.

Project sample here

Describe the bug

Started the application with npx create-react-app client
This is my project structure:

.
├── package-lock.json
├── package.json
├── public
│   ├── favicon.ico
│   ├── index.html
│   └── manifest.json
└── src
    ├── App.js
    ├── App.test.js
    ├── css
    │   └── mystyles.css
    ├── img
    │   ├── landing.jpg
    │   ├── logo-2.jpg
    │   └── logo-transp2.png
    ├── index.js
    ├── sass
    │   └── mystyles.scss
    ├── setupTests.js
    └── user
        ├── components
        │   └── Appointments.js
        └── pages
            └── Dashboard.js

src/Dashboard.js

import React, { Fragment } from 'react';

import Appointments from '../components/Appointments';

const Dashboard = () => {
  return (
    <Fragment>
      <Appointments />
    </Fragment>
  );
};

export default Dashboard;

Appointments.js

import React from './node_modules/react';

const Appointments = () => {
  return (
    <div>
      This is an ultra simple component
    </div>
  );
};

export default Appointments;

The output in the console when I run npm start:

Failed to compile.

./src/user/components/Appointments.js
Module not found: Can't resolve './node_modules/react' in '<path-to-project>/client/src/user/components'

I Did recover my dependencies. I'm using npm.

I did:

  • rm -fr node_modules package-lock.json

Then:

  • npm install -g npm@latest
  • npm install

And it didn't fixed my project

$ npm --version
6.14.5

Searches in Google and in the User Guide?

Can't resolve './node_modules/react'

Answers found:

Which does not apply to my case.
My paths are correct, I done the project recovery, I have ./node_modules/react, react is on my dependencies

Environment

I'm running macOS Catalina Version 10.15.4

After running npx create-react-app --info:

npx: installed 98 in 13.607s

Environment Info:

  current version of create-react-app: 3.4.1
  running from /Users/camilocoelho/.npm/_npx/6830/lib/node_modules/create-react-app

  System:
    OS: macOS 10.15.4
    CPU: (4) x64 Intel(R) Core(TM) i5-4250U CPU @ 1.30GHz
  Binaries:
    Node: 12.13.1 - /usr/local/bin/node
    Yarn: Not Found
    npm: 6.14.5 - /usr/local/bin/npm
  Browsers:
    Chrome: 83.0.4103.61
    Firefox: 76.0.1
    Safari: 13.1
  npmPackages:
    react: ^16.13.1 => 16.13.1 
    react-dom: ^16.13.1 => 16.13.1 
    react-scripts: 3.4.1 => 3.4.1 
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

  1. git clone https://github.com/Kmelow/debug-cra
  2. cd debug-cra
  3. npm i
  4. npm start

Expected behavior

Successful compilation when calling another component from a component

Actual behavior

Outputs compilation error:

Failed to compile.

./src/user/components/Appointments.js
Module not found: Can't resolve './node_modules/react' in '<path-to-project>/client/src/user/components'

Reproducible demo

Project sample here

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions