尝试 运行 npm start 命令时出错

Error when trying to run npm start command

我正在尝试创建一个反应项目,我有 运行 npx create-react-app hello-react --use-npm 然后 cd hello-react 但是当我 npm start 时,这个错误已经显示:

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\develompent\Desktop\react\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\develompent\Desktop\react\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\develompent\AppData\Roaming\npm-cache\_logs20-08-30T18_43_59_773Z-debug.log

C:\Users\develompent\Desktop\react>cd hello-react

C:\Users\develompent\Desktop\react\hello-react>npm start

> hello-react@0.1.0 start C:\Users\develompent\Desktop\react\hello-react
> react-scripts start

i 「wds」: Project is running at http://192.168.137.1/
i 「wds」: webpack output is served from
i 「wds」: Content not from webpack is served from C:\Users\develompent\Desktop\react\hello-react\public
i 「wds」: 404s will fallback to /
Starting the development server...

events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: spawn powershell ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn powershell',
  path: 'powershell',
  spawnargs: [
    '-NoProfile',
    '-NonInteractive',
    '–ExecutionPolicy',
    'Bypass',
    '-EncodedCommand',
    'UwB0AGEAcgB0ACAAIgBgACIAaAB0AHQAcAA6AC8ALwBsAG8AYwBhAGwAaABvAHMAdAA6ADMAMAAwADAAYAAiACIA'
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hello-react@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hello-react@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\develompent\AppData\Roaming\npm-cache\_logs20-08-30T18_44_47_550Z-debug.log

我曾尝试删除 node_modules 然后我又安装了它,但同样的问题仍然存在 我还尝试 运行 以管理员身份打开 cmd,但没有显示任何错误

创建一个新文件夹并尝试这样做:

npx create-react-app my-app
cd my-app
npm start

您需要在您的机器上安装 Node >= 8.10 和 npm >= 5.6

https://reactjs.org/docs/create-a-new-react-app.html

您可以尝试在C:\windows\System32

路径下重新安装node

或者你可以

按照以下步骤操作:

  • npm cache clean --force
  • 删除 node_modules 文件夹
  • 删除package-lock.json文件
  • npm install

使用这些命令为项目降级 React 脚本

npm install react-scripts@2.1.8
npm start