[英]npm start fails after creating a new react project using create-react-app
I'm having some trouble with react-scripts after creating a new react project.创建新的反应项目后,我在使用反应脚本时遇到了一些问题。 I created/initialised the project using npx create-react-app dashboard
.我使用npx create-react-app dashboard
创建/初始化了项目。 After going inside the dashboard folder and running npm start
(without doing anything else beforehand), I get the following error:进入仪表板文件夹并运行npm start
(事先不做任何其他事情)后,我收到以下错误:
>npm start
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
> dashboard@0.1.0 start
> react-scripts start
'react-scripts' is not recognized as an internal or external command,
operable program or batch file.
I have checked the package.json file and it does have react-scripts listed (v5.0.1, full package.json below) and checking the node_modules folder shows a react-scripts folder there and react-scripts files (cmd, ps1 and 1 with no extension) inside the .bin folder too.我检查了 package.json 文件,它确实列出了 react-scripts(v5.0.1,下面的完整 package.json)并检查 node_modules 文件夹显示了 react-scripts 文件夹和 react-scripts 文件(cmd、ps1 和 1没有扩展名)也在 .bin 文件夹中。
I've tried clearing the npm cache ( npm cache clean -f
), installing things again (deleting package-lock.json and node_modules folder then running npm install
) and nothing seems to change.我尝试清除 npm 缓存( npm cache clean -f
),再次安装(删除 package-lock.json 和 node_modules 文件夹,然后运行npm install
),似乎没有任何改变。
I've also tried running npm start
in command prompt, powershell and powershell as an admin.我还尝试以管理员身份在命令提示符、powershell 和 powershell 中运行npm start
。 I've also tried restarting my PC and retrying too without any luck.我也尝试过重新启动我的电脑并重试,但没有任何运气。
Specs:
Edition: Windows 10 Pro
Version: 21H2
OS build: 19044.1766
Experience Windows Feature Experience Pack: 120.2212.4180.0
Node JS version: 16.15.1
npm version: 8.11.0
full package.json:完整的 package.json:
{
"name": "dashboard",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
If anyone has any ideas on how to fix this, I'd appreciate the help.如果有人对如何解决此问题有任何想法,我将不胜感激。 Let me know if you need/want any more info that might help debug this issue如果您需要/想要更多可能有助于调试此问题的信息,请告诉我
As suggested in this comment: https://stackoverflow.com/a/68394617/2371266 , running npm config set script-shell powershell
seems to have worked.正如此评论中所建议的: https ://stackoverflow.com/a/68394617/2371266,运行npm config set script-shell powershell
似乎已经奏效。 I tried deleting the script-shell config afterwards and retrying and got the original error again so I'm assuming it is defaulting to something else and that's making things freak out a bit.之后我尝试删除 script-shell 配置并重试并再次收到原始错误,所以我假设它默认为其他内容,这让事情变得有点怪异。 I guess I'll just keep it pointed at powershell for now.我想我现在只是将它指向powershell。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.