如何修复 npm ERR!缺少脚本:从反应开始

Posted

技术标签:

【中文标题】如何修复 npm ERR!缺少脚本:从反应开始【英文标题】:How to fix npm ERR! missing script: start in react 【发布时间】:2020-01-11 20:25:17 【问题描述】:

当我运行 npm start 时,我看到了错误。

我试过了,但没用:https://techoverflow.net/2019/04/01/how-to-fix-npm-err-missing-script-start/

“私人”:真的, “脚本”: "dev": "npm 运行开发", "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", "watch-poll": "npm run watch -- --watch-poll", "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config。 js", "prod": "npm 运行生产", “生产”:“跨环境 NODE_ENV=生产 node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js” , “开发依赖”: "axios": "^0.17.1", "babel-plugin-syntax-dynamic-import": "^6.18.0", "babel-plugin-transform-class-properties": "^6.24.1", "babel-preset-react": "^6.23.0", "bootstrap-sass": "^3.3.7", “跨环境”:“^5.2.0”, "jquery": "^3.2", "laravel-mix": "^1.0", "lodash": "^4.17.11", “反应”:“^16.5.1”, “反应域”:“^16.4.0” , “依赖”: "antd": "^3.12.4", "babel-plugin-import": "^1.8.0", "css-loader": "^2.1.0", "少": "^3.9.0", "less-loader": "^4.1.0", “时刻”:“^2.22.2”, "时刻-时区": "^0.5.21", “反应插件更新”:“^15.6.2”, "react-redux": "^5.0.7", “反应响应模式”:“^4.0.1”, "react-router-dom": "^4.3.1", "redux": "^4.0.0", "redux-thunk": "^2.3.0", “样式加载器”:“^0.23.1”

【问题讨论】:

作为解决方案,我已经运行 npm run dev,因为我需要 app.js 中的输出 【参考方案1】:

您的 package.json 中缺少名为“start”的脚本。查看脚本/开始行并在您的 package.json 中添加相同(但为您的文件修改)


"private": true,
"scripts": 
    "dev": "npm run development",
    "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch-poll": "npm run watch -- --watch-poll",
    "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "prod": "npm run production",
    "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "start": "node index.js"
,
"devDependencies": 
    "axios": "^0.17.1",
    "babel-plugin-syntax-dynamic-import": "^6.18.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-preset-react": "^6.23.0",
    "bootstrap-sass": "^3.3.7",
    "cross-env": "^5.2.0",
    "jquery": "^3.2",
    "laravel-mix": "^1.0",
    "lodash": "^4.17.11",
    "react": "^16.5.1",
    "react-dom": "^16.4.0"
,
"dependencies": 
    "antd": "^3.12.4",
    "babel-plugin-import": "^1.8.0",
    "css-loader": "^2.1.0",
    "less": "^3.9.0",
    "less-loader": "^4.1.0",
    "moment": "^2.22.2",
    "moment-timezone": "^0.5.21",
    "react-addons-update": "^15.6.2",
    "react-redux": "^5.0.7",
    "react-responsive-modal": "^4.0.1",
    "react-router-dom": "^4.3.1",
    "redux": "^4.0.0",
    "redux-thunk": "^2.3.0",
    "style-loader": "^0.23.1"

【讨论】:

【参考方案2】:

我尝试在将来从头开始删除并重新安装所有内容,即项目文件夹并运行最新的 react 安装,它对我有用。

再试一次:npm i -g create-react-app(没有版本号,在你打算工作的文件夹中)

提示:有时不要因为害怕而使调试过于复杂,有时尽管听写教程,但也不要尝试不同版本的软件。

祝你好运!

实际上,这个 YouTube 视频 @ 3:30 分钟为潜在的指导提供了一个类似的解决方案! - bc 错误并不完全相同。

https://youtu.be/T2MhVxJxsL0?t=209

【讨论】:

以上是关于如何修复 npm ERR!缺少脚本:从反应开始的主要内容,如果未能解决你的问题,请参考以下文章

尝试在 Heroku 上托管 VueJS 应用程序。在 heroku 日志中获取“npm ERR!缺少脚本:开始”,在我的页面上获取“应用程序错误”

如何修复缺少的脚本错误和 npm start?

无法在 Testcafe 错误消息中运行 percy 快照测试:npm ERR!缺少脚本:test:percy

npm 错误!缺少脚本:将反应应用程序部署到heroku时构建

Heroku 网站:npm 错误!缺少脚本:开始

Npm 错误!缺少脚本:部署到 heroku 时开始