Laravel 5.6+Bootstrap项目执行npm run dev报错求助
Hey there, that cross-env: not found error is a super common hiccup when working with Laravel Mix. Let's break down how to fix it quickly:
Why this happens
When you run npm run dev, Laravel Mix relies on the cross-env package to set your NODE_ENV environment variable. The error means this package either wasn't installed at all, or the installation got corrupted along the way.
Step-by-step fixes
First, do a clean reinstall of dependencies
Sometimes thenode_modulesfolder or lock files get messed up. Run these commands in your project root:rm -rf node_modules package-lock.json npm installIf you use Yarn instead, swap out the last command with
yarn install.If clean install doesn't work, manually install cross-env
Force-install the package as a development dependency:npm install cross-env --save-devFor Yarn users, use this instead:
yarn add cross-env --devTry running the dev command again
Once the installation finishes, fire up the dev script again:npm run dev
Quick note for Linux/macOS users
If you hit permission errors during installation, you can try running the commands with sudo (e.g., sudo npm install), but it's better to fix your npm permissions long-term to avoid relying on sudo for package installs.
内容的提问来源于stack exchange,提问作者user2339232

