Chrome Music Lab仓库chords模块本地运行失败求助
Hey there, let's get your Chrome Music Lab chords module up and running locally! The error you're seeing (The CLI moved into a separate...) is super common with newer Webpack versions—here's what's going on and how to fix it:
What's the Problem?
Starting with Webpack 4, the command-line interface (CLI) was split into a separate package (webpack-cli) instead of being included in the main webpack package. When you run webpack -p directly, your system can't find the CLI tools it needs to execute the command.
Step-by-Step Solutions
Option 1: Install Webpack CLI Locally (Recommended)
This keeps dependencies tied to your project and avoids global version conflicts:
- First, install the CLI as a development dependency:
npm install webpack-cli --save-dev - Then run the build command using
npx(which uses the local CLI version):npx webpack -p
Option 2: Install Webpack CLI Globally
If you want to use webpack commands across multiple projects without reinstalling:
npm install -g webpack-cli
After this, you can run webpack -p directly as you tried before.
Bonus Check: Use the Project's Built-in Scripts
Take a quick look at the project's package.json file—many projects include pre-configured scripts in the "scripts" section. If there's a build script (like "build": "webpack -p"), you can just run:
npm run build
This is often the most reliable way, as it uses the exact Webpack version specified in the project's dependencies.
Quick Note on Version Compatibility
Before installing Webpack manually, double-check the project's package.json or README for any specified Webpack version requirements. If the project was built for an older Webpack version (like 3.x), installing the latest Webpack 5 might cause additional issues. To install a specific version, use:
npm install webpack@<version-number> --save-dev
Once you've completed these steps, your build should run successfully, and you'll be able to access the chords module locally!
内容的提问来源于stack exchange,提问作者dvdss6

