“新建项目”在 Vis-6ren">
gpt4 book ai didi

node.js - npm install 成功,但 npm run start 无法找到 rimraf 和 react-scripts,尽管它们已安装

转载 作者:行者123 更新时间:2023-12-03 13:38:08 25 4
gpt4 key购买 nike

运行 Windows 10(内部版本 18362),使用 Node.js v10.16.0、npm v6.9.0 和 .Net Core v2.2.300。我通过"file"->“新建项目”在 Visual Studio 2017 中创建了一个示例 React/Redux 应用程序,选择 ASP.NET Core Web 应用程序,然后选择 React.js 和 Redux。但是,当通过 Visual Studio 启动应用程序时,浏览器遇到 500 错误并显示:

An unhandled exception occurred while processing the request.
AggregateException: One or more errors occurred. (One or more errors occurred. (The NPM script 'start' exited without indicating that the create-react-app server was listening for requests. The error output was: 'rimraf' is not recognized as an internal or external command,

operable program or batch file.
npm ERR! code ELIFECYCLE

npm ERR! errno 1
npm ERR! WebApplication1@0.1.0 start: `rimraf ./build && react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the WebApplication1@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

首先,我卸载并重新安装了node和npm,删除了node_modules并重新运行了npm install。我在重新安装 Node 之前和之后重新启动。

我知道 rimraf 安装在本地 .\node_modules 目录中,因为我可以成功运行 .\node_modules\.bin\rimraf。如果我运行 .\node_modules\.bin\react-scripts startreact-scripts start 会成功启动应用程序的 React 部分,但是为什么 npm 找不到这个?

据我了解,npm 在脚本执行时将本地 node_modules\.bin 添加到 PATH 中,但它仍然无法找到 rimrafreact-scripts 尽管如果提供 shell 的绝对路径,则可以访问它们。

我还尝试将 .\node_modules\.bin 添加到我的系统路径中,这允许我(假设我位于应用程序目录的根目录中)只运行 react-脚本启动并加载应用程序,但npm run start仍然失败。

这是我的 package.json:

{
"name": "WebApplication1",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "^4.3.1",
"jquery": "3.3.1",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-redux": "^5.0.6",
"react-router-bootstrap": "^0.24.4",
"react-router-dom": "^4.2.2",
"react-router-redux": "^5.0.0-alpha.8",
"react-scripts": "^1.1.5",
"reactstrap": "^6.3.0",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0",
"rimraf": "^2.6.2"
},
"devDependencies": {
"ajv": "^6.0.0",
"babel-eslint": "^7.2.3",
"cross-env": "^5.2.0",
"eslint": "^4.1.1",
"eslint-config-react-app": "^2.1.0",
"eslint-plugin-flowtype": "^2.50.3",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.11.1"
},
"eslintConfig": {
"extends": "react-app"
},
"scripts": {
"start": "rimraf ./build && react-scripts start",
"build": "react-scripts build",
"test": "cross-env CI=true react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"lint": "eslint ./src/"
}
}

最佳答案

遇到了同样的问题,请选择调试选项 [您的应用程序的名称],而不是调试选项 IIS Express。

关于node.js - npm install 成功,但 npm run start 无法找到 rimraf 和 react-scripts,尽管它们已安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56942659/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com