在“关于webpack”上运行React App时出错

时间:2018-10-31 07:27:01

标签: reactjs create-react-app

我正在使用create-react-app。运行npm start时,出现以下错误。

我已经尝试了终端给出的所有步骤(请参见下文)。就是行不通。我也曾尝试卸载并安装webpack,但到目前为止还没有运气。我该如何解决?

  

项目依赖关系树可能存在问题。是
  可能不是Create React App中的错误,而是您需要解决的问题
  本地。          Create React App提供的react-scripts软件包需要依赖项:

 "webpack": "4.19.1"
   Don't try to install it manually: your package manager does it    automatically. However, a different version of webpack was detected   
     

在树的上方:

 /Users/seertech/node_modules/webpack (version: 4.23.1)
   Manually installing incompatible versions is known to cause    hard-to-debug issues.
   If prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an    .env file in your project. That will permanently disable this
     

消息,但您可能会遇到其他问题。          要修复依赖关系树,请尝试按照确切的顺序执行以下步骤:

 1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
 2. Delete node_modules in your project folder.
 3. Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
 4. Run npm install or yarn, depending on the package manager you use.
   In most cases, this should be enough to fix the problem. If this has    not helped, there are a few other things you can try:

 5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
    This may help because npm has known issues with package hoisting which may get resolved in future versions.

 6. Check if /Users/seertech/node_modules/webpack is outside your project directory.
    For example, you might have accidentally installed something in your home folder.

 7. Try running npm ls webpack in your project folder.
    This will tell you which other package (apart from the expected react-scripts) installed webpack.
   If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file    in your project. That would permanently disable this preflight
     

检查是否要继续进行操作。          附言我们知道此消息很长,但是请阅读上述步骤:-)我们希望您对他们有所帮助!          npm ERR!代码ELIFECYCLE npm ERR! errno 1 npm错误! react-client@0.1.0开始:react-scripts start npm ERR!出口   状态1 npm错误! npm ERR!在react-client@0.1.0启动时失败   脚本。 npm ERR! npm可能不是问题。有   上面可能还有其他日志记录输出。

2 个答案:

答案 0 :(得分:0)

这是因为NPM软件包安装在该文件夹上方的文件夹中,可能是错误的。要解决此问题,请从项目文件夹开始,然后cd ../进入上述文件夹,执行ls。如果看到不应该存在的node_modules文件夹,请将其删除。如果不是,请再次cd ../,然后再次ls。重复直到找到令人讨厌的node_modules并将其删除。

答案 1 :(得分:0)

这意味着您需要安装“ webpack”:“ 4.19.1”,但要安装版本:4.23.1。要在package.json中解决此问题,请添加以下内容:

resolutions:{
      "webpack": "4.19.1"
}

在这里我们告诉我们无论如何都希望webpack始终为“ 4.19.1”版本。如果重新安装所有依赖项,则将强制Webpack版本为“ 4.19.1”。