Windows 10克隆仓库后执行npm脚本报错:Missing script: build
Hey there! I see exactly what's going on here—this is a classic cross-platform shell syntax issue between Unix-like systems (where you were probably developing originally) and Windows.
The Root Cause
Your start script uses a Unix-style semicolon ; to chain two commands:
"start": "npm run build; webpack-dev-server --open --mode development"
On Windows, the default command prompt (CMD) doesn't recognize ; as a command separator. Instead, it treats the entire string build; as the name of the npm script you're trying to run. Since your package.json only has a script named build (not build;), npm throws that missing script error.
Quick Fixes
Here are a few ways to fix this, ordered by simplicity and best practice:
Use
&&(Recommended for Sequential Execution)
Replace the semicolon with&&—this tells Windows (and Unix systems) to run the second command only if the first one succeeds:"scripts": { // ... other scripts "start": "npm run build && webpack-dev-server --open --mode development" }Use
&for Unconditional Execution
If you want the second command to run even if the first fails, use a single&instead:"start": "npm run build & webpack-dev-server --open --mode development"Cross-Platform Script Runner (Most Robust)
For full cross-platform compatibility (so you don't hit this issue again if switching between OSes), usenpm-run-all:- First install it as a dev dependency:
npm install --save-dev npm-run-all - Then update your scripts to use sequential execution:
"scripts": { // ... other scripts "build": "webpack --mode development", "start:dev": "webpack-dev-server --open --mode development", "start": "run-s build start:dev" }
run-sstands for "run sequential"—it will executebuildfirst, thenstart:dev, no matter what OS you're on.- First install it as a dev dependency:
How to Test
After updating your package.json, save it and re-run:
npm start
This should now correctly run the build script followed by the dev server without errors.
内容的提问来源于stack exchange,提问作者Izzy Moppin

