NestJS执行npm run start报错:Missing script: "start" 求助
NestJS运行
npm run start提示缺少start脚本的解决办法 刚完成NestJS安装,跟着官方文档在VSCode里启动项目,执行npm run start时却收到错误提示:Missing script: "start",但项目的package.json明明配置了start脚本。以下是完整错误日志和package.json配置:
完整错误日志
0 verbose cli /var/lib/snapd/snap/node/6895/bin/node /var/lib/snapd/snap/node/6895/bin/npm 1 info using npm@8.19.2 2 info using node@v16.18.1 3 timing npm:load:whichnode Completed in 0ms 4 timing config:load:defaults Completed in 2ms 5 timing config:load:file:/var/lib/snapd/snap/node/6895/lib/node_modules/npm/npmrc Completed in 2ms 6 timing config:load:builtin Completed in 2ms 7 timing config:load:cli Completed in 2ms 8 timing config:load:env Completed in 1ms 9 timing config:load:project Completed in 5ms 10 timing config:load:file:/home/ramanm/.npmrc Completed in 0ms 11 timing config:load:user Completed in 0ms 12 timing config:load:file:/var/lib/snapd/snap/node/6895/etc/npmrc Completed in 3ms 13 timing config:load:global Completed in 3ms 14 timing config:load:validate Completed in 1ms 15 timing config:load:credentials Completed in 1ms 16 timing config:load:setEnvs Completed in 1ms 17 timing config:load Completed in 19ms 18 timing npm:load:configload Completed in 19ms 19 timing npm:load:mkdirpcache Completed in 6ms 20 timing npm:load:mkdirplogs Completed in 1ms 21 verbose title npm run start 22 verbose argv "run" "start" 23 timing npm:load:setTitle Completed in 2ms 24 timing config:load:flatten Completed in 3ms 25 timing npm:load:display Completed in 6ms 26 verbose logfile logs-max:10 dir:/home/ramanm/.npm/_logs 27 verbose logfile /home/ramanm/.npm/_logs/2022-11-16T12_34_58_739Z-debug-0.log 28 timing npm:load:logFile Completed in 6ms 29 timing npm:load:timers Completed in 0ms 30 timing npm:load:configScope Completed in 0ms 31 timing npm:load Completed in 41ms 32 silly logfile start cleaning logs, removing 1 files 33 silly logfile done cleaning log files 34 timing command:run Completed in 11ms 35 verbose stack Error: Missing script: "start" 35 verbose stack 35 verbose stack Did you mean one of these? 35 verbose stack npm star # Mark your favorite packages 35 verbose stack npm stars # View packages marked as favorites 35 verbose stack 35 verbose stack To see a list of scripts, run: 35 verbose stack npm run 35 verbose stack at RunScript.run (/var/lib/snapd/snap/node/6895/lib/node_modules/npm/lib/commands/run-script.js:98:13) 35 verbose stack at async module.exports (/var/lib/snapd/snap/node/6895/lib/node_modules/npm/lib/cli.js:78:5) 36 verbose cwd /home/ramanm/workspace/nestPrac 37 verbose Linux 5.15.76-1-MANJARO 38 verbose node v16.18.1 39 verbose npm v8.19.2 40 error Missing script: "start" 40 error 40 error Did you mean one of these? 40 error npm star # Mark your favorite packages 40 error npm stars # View packages marked as favorites 40 error 40 error To see a list of scripts, run: 40 error npm run 41 verbose exit 1 42 timing npm Completed in 68ms 43 verbose code 1 44 error A complete log of this run can be found in: 44 error /home/ramanm/.npm/_logs/2022-11-16T12_34_58_739Z-debug-0.log
项目package.json配置
{ "name": "prac", "version": "0.0.1", "description": "", "author": "", "private": true, "license": "UNLICENSED", "scripts": { "prebuild": "rimraf dist", "build": "nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "start": "nest start", "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", "start:prod": "node dist/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "jest --config ./test/jest-e2e.json" }, "dependencies": { "@nestjs/common": "^9.0.0", "@nestjs/core": "^9.0.0", "@nestjs/platform-express": "^9.0.0", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", "rxjs": "^7.2.0" }, "devDependencies": { "@nestjs/cli": "^9.0.0", "@nestjs/schematics": "^9.0.0", "@nestjs/testing": "^9.0.0", "@types/express": "^4.17.13", "@types/jest": "28.1.8", "@types/node": "^16.0.0", "@types/supertest": "^2.0.11", "@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/parser": "^5.0.0", "eslint": "^8.0.1", "eslint-config-prettier": "^8.3.0", "eslint-plugin-prettier": "^4.0.0", "jest": "28.1.3", "prettier": "^2.3.2", "source-map-support": "^0.5.20", "supertest": "^6.1.3", "ts-jest": "28.0.8", "ts-loader": "^9.2.3", "ts-node": "^10.0.0", "tsconfig-paths": "4.1.0", "typescript": "^4.7.4" }, "jest": { "moduleFileExtensions": [ "js", "json", "ts" ], "rootDir": "src", "testRegex": ".*\\.spec\\.ts$", "transform": { "^.+\\.(t|j)s$": "ts-jest" }, "collectCoverageFrom": [ "**/*.(t|j)s" ], "coverageDirectory": "../coverage", "testEnvironment": "node" } }
解决步骤
- 确认终端路径正确:运行
pwd命令,检查输出是否为/home/ramanm/workspace/nestPrac。如果不是,执行cd /home/ramanm/workspace/nestPrac切换到项目根目录,再重新运行npm run start。 - 保存package.json:在VSCode中按
Ctrl+S(Linux/Windows)或Cmd+S(Mac)保存配置文件,避免编辑器未同步到磁盘导致npm读取旧配置。 - 清除缓存并重装依赖:依次执行
npm cache clean --force和npm install,完成后再尝试启动项目。 - 直接测试nest命令:运行
nest start,如果能正常启动,说明npm脚本本身无问题;如果报错,执行npm list @nestjs/cli检查本地是否安装了cli,未安装则运行npm install -D @nestjs/cli。
内容的提问来源于stack exchange,提问作者Raman Maharjan
相关产品推荐
相关产品推荐

