【发布时间】:2018-06-11 09:42:11
【问题描述】:
我正在完成一个项目,我对 React 很陌生。
我试图安装一个名为 react-toastify 的新软件包,突然我正在创建的几乎完成的项目向我显示此错误:
./node_modules/react/index.js
Module build failed: Error: ENOENT: no such file or directory, open
'/Users/mynamehere/react/projectnamehere/frontend/node_modules/react/index.js'
当我检查提到的目录时,该文件确实不存在。但这很有效,因为我在这个项目上工作了很长时间。
我尝试使用 npm install 重新安装所有内容,但无济于事。
这是我在第一次出现错误时从.npm/_logs 获取的初始日志。
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@5.0.0
3 info using node@v8.0.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle frontend@0.1.0~prestart: frontend@0.1.0
6 silly lifecycle frontend@0.1.0~prestart: no script for prestart, continuing
7 info lifecycle frontend@0.1.0~start: frontend@0.1.0
8 verbose lifecycle frontend@0.1.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle frontend@0.1.0~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/edper/react/readable-redux/frontend/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/share/dotnet:/usr/local/go/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
10 verbose lifecycle frontend@0.1.0~start: CWD: /Users/edper/react/readable-redux/frontend
11 silly lifecycle frontend@0.1.0~start: Args: [ '-c', 'react-scripts start' ]
12 error cb() never called!
13 error This is an error with npm itself. Please report this error at:
14 error <https://github.com/npm/npm/issues>
我尝试按照以下建议删除node_modules 目录,但我得到了与上次相同的错误,如下所示:
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! frontend@0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the frontend@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
【问题讨论】:
-
尝试删除node_modules文件夹,然后运行
npm install -
我正在按照您的建议尝试,但我遇到了与上次相同的错误。
-
删除所有节点模块。点击 npm 已过时。检查所有依赖项发生了什么变化。更新包 json 并点击 npm install。请注意新节点模块中可能存在重大更改,因此您需要检查所有更新模块的更改日志
-
@hannadrehman 可能是因为我之前在这个节点上使用了一个较旧的节点,所以它坏了,我想在 v7 左右,就在昨天,我安装了 v8 节点?但是在我安装
react-toastify包之前一切正常。我也不熟悉node,如果再次出现故障,我不知道是否可以按照您的建议进行操作。 -
是的,这是可能的,因为每个主要版本都会有重大更改,随着节点的快速发展,许多功能变得不受支持。这就是为什么您也应该更新节点模块的原因。当您点击
npm outdated时,您还将获得发布信息。在更新之前检查发行说明和支持等。@Edper
标签: reactjs npm node-modules