Windows7下Laravel5.4.1执行npm run dev命令报错求助
Let’s work through your issues step by step—you’ve got two distinct problems here: a Windows-specific environment variable syntax error, and a misconfigured path in your webpack.mix.js that’s throwing the Path must be a string TypeError.
1. Fix the NODE_ENV Syntax for Windows
Windows doesn’t recognize the Unix-style NODE_ENV=development syntax you’re using in your package.json scripts. That’s why you first got the "'node_modules' is not recognized" error—Windows was trying to run NODE_ENV as a command instead of setting it as an environment variable.
You already have cross-env installed (it’s in your devDependencies), so let’s update your scripts to use it properly:
Replace your existing scripts section in package.json with this:
"scripts": { "dev": "npm run development", "development": "cross-env NODE_ENV=development node node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", "watch": "cross-env NODE_ENV=development node node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", "watch-poll": "npm run watch -- --watch-poll", "hot": "cross-env NODE_ENV=development node node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", "prod": "npm run production", "production": "cross-env NODE_ENV=production node node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" }
Key fixes:
- Added
cross-envat the start of each script that setsNODE_ENV—this handles environment variable setup consistently across Windows and Unix systems. - Explicitly added
nodebefore thenode_modules/webpack/...paths to ensure Windows locates the Node executable correctly.
2. Fix the Path must be a string TypeError
Looking at your error stack trace, the issue originates at webpack.mix.js:17:5 in the mix.sass() call. This means the first argument you’re passing to mix.sass() is undefined (not a valid string path).
Open your webpack.mix.js file and go to line 17. You’ll likely see something like:
mix.sass(undefined, 'public/css'); // OR mix.sass('', 'public/css'); // OR mix.sass(someUndefinedVariable, 'public/css');
Fix this by passing a valid path to your main Sass file. For a default Laravel 5.4 setup, this should be:
mix.sass('resources/assets/sass/app.scss', 'public/css');
Double-check that the source file exists at that path—if you renamed or moved your Sass files, update the path accordingly.
3. Clean and Reinstall Dependencies
Corrupted node_modules files can cause odd behavior. Let’s do a clean install:
- Delete the
node_modulesfolder in your project root. - Delete the
package-lock.jsonfile. - Run
npm installin your project directory to reinstall all dependencies fresh.
4. Verify Node/NPM Paths (Optional)
Make sure Node.js and npm are properly added to your Windows PATH:
- Open Command Prompt and run
node -v—it should outputv8.9.3. - Run
npm -v—it should output5.5.1.
If either command fails, add the Node.js installation directory (usuallyC:\Program Files\nodejs\) to your system PATH.
After making these changes, try running npm run dev again—it should work without the previous errors.
内容的提问来源于stack exchange,提问作者Anil Kumar Sahu

