Can't resolve module (not found) in React.js

前端 未结 15 1225
太阳男子
太阳男子 2020-12-07 22:03

I can\'t believe that I\'m asking an obvious question, but I still get the error in console log.

Console says that it can\'t find the module in the directory, but I\

相关标签:
15条回答
  • 2020-12-07 22:20

    In my case I rename a component file, an VS Code add the below line of code for me:

    import React, { Component } from "./node_modules/react";
    

    So I fixed by removing the: ./node_modules/

    import React, { Component } from "react";
    

    Cheers!

    0 讨论(0)
  • 2020-12-07 22:22

    You need to be in project folder, if you are in src or public you have to come out of those folders. Suppose your react-project name is 'hello-react' then cd hello-react

    0 讨论(0)
  • 2020-12-07 22:25

    Check for the import statements.It should be ended with semicolon. If you miss any, you will get this error.

    Also check whether following import statement added in you component.

    import { threadId } from 'worker_threads';

    If so remove that line. It works for me.

    0 讨论(0)
  • 2020-12-07 22:26

    You can try to execute 'npm install' in the app folder. This might also solve the problem. It worked for me.

    0 讨论(0)
  • 2020-12-07 22:28

    Deleted the package-lock.json file & then ran

    npm install
    

    Read further

    0 讨论(0)
  • 2020-12-07 22:29

    If you create an application with react-create-app, don't forget set environment variable:

    NODE_PATH=./src
    

    Or add to .env file to your root folder;

    0 讨论(0)
提交回复
热议问题