You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows7下Laravel5.4.1执行npm run dev命令报错求助

Troubleshooting npm Run Failures in Laravel 5.4 on Windows 7

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-env at the start of each script that sets NODE_ENV—this handles environment variable setup consistently across Windows and Unix systems.
  • Explicitly added node before the node_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_modules folder in your project root.
  • Delete the package-lock.json file.
  • Run npm install in 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 output v8.9.3.
  • Run npm -v—it should output 5.5.1.
    If either command fails, add the Node.js installation directory (usually C:\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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:08:55