node.js - npm start 不起作用。我已经尝试了一切。我很困惑

标签 node.js reactjs npm webpack

因此,每当我在 React 项目中运行 npm start 时,都会出现以下错误:

myapp@0.1.0 start C:\Users\AyaLe\Desktop\React\myapp react-scripts start

There might be a problem with the project dependency tree. It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

"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 higher up in the tree:

C:\Users\AyaLe\node_modules\webpack (version: 3.10.0)

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 message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  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:

  1. 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.

  2. Check if C:\Users\AyaLe\node_modules\webpack is outside your project directory. For example, you might have accidentally installed something in your home folder.

  3. 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 check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! myapp@0.1.0 start: react-scripts start npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the myapp@0.1.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR!
C:\Users\AyaLe\AppData\Roaming\npm-cache_logs\2018-12-02T10_15_24_630Z-debug.log

此外,每当我尝试安装 webpack-cli 时,它都会要求我安装,它会给我另一个错误

最佳答案

看起来您已经全局安装了 "webpack": "3.10.0",但您需要安装 "webpack": "4.19.1"。这导致了冲突。

您需要执行以下操作:

1. $npm uninstall -g webpack
2. $npm install -g webpack@4.19.1

这应该可以解决问题。

或者,您可以尝试删除 node_modules 文件夹,或者具体删除 node_modules 中的 webpack 文件夹,位置为:

C:\Users\AyaLe\node_modules\webpack (version: 3.10.0)

关于node.js - npm start 不起作用。我已经尝试了一切。我很困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53579310/

相关文章:

javascript - SvelteJS 是否将第三方库代码转换为纯 Javascript?

mysql - 在nodejs中可以同步mysql查询吗?

node.js - 在gulp-nodemon中设置端口有什么用?

javascript - 了解Node.JS使用async.waterfall如何执行外部功能

javascript - React Native SectionList scrollToLocation 不是函数

javascript - 组件如何在不将状态向上移动到组件树的情况下向其兄弟发送消息?

javascript - 将 `undefined` 转换为 `map<string, AnonymousModel>` 时出错

javascript - ReactJS 在多个组件之间保持单个 "Active"状态

javascript - 意外字符 '#'

javascript - 与您的操作系统或架构不兼容 : fsevents@1. 0.11