Yarn 1.7执行yarn s启动Webpack失败,提示命令未找到
webpack: command not found & Node Version Mismatch Issues Let’s tackle your problems one by one—they’re likely linked, so fixing the Node version first will resolve a lot of downstream headaches.
1. Resolve Node Version Mismatch
Your current Node version (10.2.1) doesn’t match the 6.9.1 specified in your package.json, which can cause dependency conflicts, broken installs, and unexpected command failures. Here’s how to fix it with nvm (Node Version Manager, the simplest way to manage multiple Node versions):
- If you don’t have nvm installed, set it up first (follow the OS-specific setup steps for nvm—no external links needed).
- Run
nvm install 6.9.1to download the exact Node version your project requires. - Switch to this version with
nvm use 6.9.1. - Verify the change with
node -v—it should outputv6.9.1.
2. Fix npm s Triggering Search Instead of Starting Webpack
npm s is a shortcut for npm search, which is why you’re getting a search-related error. To run your project’s start script correctly:
- Use the standard start command:
npm start - If your
package.jsonhas a custom script named"s", run it explicitly with:npm run s
3. Fix yarn s webpack: command not found Error
This error typically means webpack isn’t installed locally, or your script isn’t pointing to the local webpack binary. Follow these steps to resolve it:
- First, wipe corrupted dependencies by deleting your
node_modulesfolder and lock file:rm -rf node_modules yarn.lock - Reinstall dependencies with the correct Node version:
yarn install - Ensure webpack and webpack-cli are installed as dev dependencies (webpack 4+ requires webpack-cli to run):
yarn add webpack webpack-cli --dev - Double-check your
package.jsonscripts—make sure your"s"script targets the local webpack, like this (adjust flags to match your project needs):"scripts": {
"s": "webpack --mode development"
} - Run your script explicitly to avoid ambiguity:
yarn run s
After completing these steps, your webpack build should run without the "command not found" error, and your Node version will align with the project’s requirements.
内容的提问来源于stack exchange,提问作者Lucian Tarna

