简体   繁体   English

使用 create-react-app 创建新的 react 项目后,npm start 失败

[英]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.

相关问题 使用 npx create-react-app 创建应用后<myproject> ,并使用“npm start”启动应用程序我得到了下面提到的这个错误</myproject> - After creating app using npx create-react-app <myproject> , and start app by using "npm start" i got this error mentioned below 使用 create-react-app 启动 npm 错误 - npm start error with create-react-app npm 使用 create-react-app 时启动不运行 - npm start not running when using create-react-app 我正在使用“npx create-react-app”创建一个新的 reactjs 应用程序,当它完成并尝试使用“npm start”运行它时,我收到一个错误 - I'am creating a new reactjs application using “ npx create-react-app” , and when it's done and trying to run it using “npm start” , I get an error 使用 npm create-react-app 不起作用? - using npm create-react-app is not working? 使用 create-react-app (npm start) 运行项目时如何在 Chrome 上启用地理定位? - How to enable geolocation on Chrome when running a project with create-react-app (npm start)? npm run build使用create-react-app失败 - npm run build fails with create-react-app 可以用 Nodejs 开头的 Create-React-App npm 吗? - Can you use Create-React-App npm start with nodejs? create-react-app 安装,但无法通过“start”运行 - create-react-app installs, but fails to run with "start" 安装 npm create-react-app 后 ESLint 出现问题 - Problem with ESLint after installing npm create-react-app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM