NPM启动不起作用。
节点:v12.6.0 npm:6.10.0
注意:我将项目目录放入“废纸rash”中,然后在其中运行npm start
并成功运行。有谁知道它为什么起作用?
我尝试过的事情:
npx create-react-app my-app
cd my-app
npm start
安装了最新版本的npm
安装了最新版本的节点
重新安装的节点模块
删除节点和npm并重新安装
sh: react-scripts: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! new@0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the new@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! /Users/work/.npm/_logs/2019-07-09T16_26_11_301Z-debug.log
npm ls react
└──react@16.8.6
{
"name": "new",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
完整错误日志
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli '/Users/work/.nvm/versions/node/v12.6.0/bin/node',
1 verbose cli '/Users/work/.nvm/versions/node/v12.6.0/bin/npm',
1 verbose cli 'start'
1 verbose cli ]
2 info using npm@6.10.0
3 info using node@v12.6.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle new@0.1.0~prestart: new@0.1.0
6 info lifecycle new@0.1.0~start: new@0.1.0
7 verbose lifecycle new@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle new@0.1.0~start: PATH: /Users/work/.nvm/versions/node/v12.6.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/work/Documents/Summer_2019_Study/Node/odin-node/Project2:MiniMessageBoard/frontend/new/new/node_modules/.bin:/usr/local/mysql/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Users/work/.nvm/versions/node/v12.6.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Postgres.app/Contents/Versions/latest/bin
9 verbose lifecycle new@0.1.0~start: CWD: /Users/work/Documents/Summer_2019_Study/Node/odin-node/Project2:MiniMessageBoard/frontend/new/new
10 silly lifecycle new@0.1.0~start: Args: [ '-c', 'react-scripts start' ]
11 info lifecycle new@0.1.0~start: Failed to exec start script
12 verbose stack Error: new@0.1.0 start: `react-scripts start`
12 verbose stack spawn ENOENT
12 verbose stack at ChildProcess.<anonymous> (/Users/work/.nvm/versions/node/v12.6.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18)
12 verbose stack at ChildProcess.emit (events.js:203:13)
12 verbose stack at maybeClose (internal/child_process.js:1021:16)
12 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
13 verbose pkgid new@0.1.0
14 verbose cwd /Users/work/Documents/Summer_2019_Study/Node/odin-node/Project2:MiniMessageBoard/frontend/new/new
15 verbose Darwin 17.7.0
16 verbose argv "/Users/work/.nvm/versions/node/v12.6.0/bin/node" "/Users/work/.nvm/versions/node/v12.6.0/bin/npm" "start"
17 verbose node v12.6.0
18 verbose npm v6.10.0
19 error file sh
20 error code ELIFECYCLE
21 error errno ENOENT
22 error syscall spawn
23 error new@0.1.0 start: `react-scripts start`
23 error spawn ENOENT
24 error Failed at the new@0.1.0 start script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]
即使多次尝试,反应脚本也不会安装
我现在该怎么办?
我认为Node出错。我既有/ usr / local npm文件,也有nvm文件夹中的npm文件。
已解决:
令人尴尬的是我的文件夹的语法导致该文件夹无法正常工作。上面的文件夹有一个冒号':',由于某种原因,该符号已由操作系统更改为斜杠'/'。
答案 0 :(得分:1)
请在您的终端中尝试以下操作:
首先删除所有node_modules: rm -fr node_modules /
其次:
npm install npm @ latest -g
npm install -g create-react-app
npm init react-app my-app
答案 1 :(得分:0)
这可能是因为您过去可能已在全局安装create-react-app
。使用以下命令卸载早期的create-react-app
。
sudo npm uninstall -g create-react-app
删除已创建的项目目录,然后安装my-app
rm -rf my-app
npx create-react-app my-app
来源:https://create-react-app.dev/docs/getting-started/#quick-start
答案 2 :(得分:0)
按此顺序运行这些步骤
rm -rf node_modules(或者如果不起作用,请使用强制标志删除 rm -rf node_modules-强制
rm ./package-lock.json(或者,如果这不起作用,请尝试) rm。\ package-lock.json
npm运行干净(或者如果不起作用) npm缓存清理(或如果不起作用) npm缓存清理--force
npm install -g npm @ latest
npm卸载-g create-react-app npm install -g create-react-app
如果create react-app不起作用,请重新安装 npm install --save react react-dom react-scripts(以及其他依赖项)
答案 3 :(得分:0)
我遇到了和你一样的问题。 我尝试了这篇文章中的所有答案,但没有一个对我有帮助。 我在路径上遇到了麻烦,它有一个不被接受的字符(在我的例子中是双点 ':')。
我修改了路径,问题解决了。 也许正是因为这个原因,您的项目在垃圾桶上运行。
检查您的路径以确保它是正确的并且不包含不被接受的字符。也可以尝试将项目文件夹移动到磁盘的根目录,然后尝试从那里启动。