首页 > 解决方案 > 仅在 Documents 目录中运行 create-react-app 后,npm start 无法正常工作

问题描述

我整天都在与这个问题作斗争,但仍然无法弄清楚我错过了什么。我一直在计算机上的 Documents 目录下创建我的项目,但是在使用 create-react-app 后尝试启动项目时,我开始收到以下错误。

my-app@0.1.0 start C:\Users\{user}\Documents\B&R Fun\nginx_test_deploy\my-app

react-scripts start

'R' is not recognized as an internal or external command,
operable program or batch file.
internal/modules/cjs/loader.js:985
  throw err;
  ^

Error: Cannot find module 'C:\Users\{user}\Documents\react-scripts\bin\react-scripts.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.Module._load (internal/modules/cjs/loader.js:864:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-app@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\{user}\AppData\Roaming\npm-cache\_logs\2020-03-30T21_02_14_553Z-debug.log

有趣的是,在我的桌面上运行完全相同的命令会创建一个没有错误的应用程序。我是否缺少某些可能会影响在“文档”文件夹下创建的应用程序的配置?

标签: node.jsreactjsnpmcreate-react-appnpm-start

解决方案


您应该尝试清除并重新安装 node_modules。您可以通过运行以下命令来执行此操作。

rm -rf node_modules package-lock.json && npm install && npm start

此外,升级到更高版本的nodenpm


推荐阅读