Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
0xBradock opened this issue Jun 1, 2020 · 2 comments
Closed

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

0xBradock opened this issue Jun 1, 2020 · 2 comments

Comments

@0xBradock
Copy link

0xBradock commented Jun 1, 2020

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

@0xBradock
Copy link
Author

Hello,

I had a silly typo error.
Fixed it

@JackRKelly
Copy link

JackRKelly commented Jun 1, 2020

I just was fixing it haha,

./src/user/components/Appointments.js:
import react from "react"

@lock lock bot locked and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants