Framework: [5.4] "Npm run" commands don't work on windows.

Created on 25 Jan 2017  路  24Comments  路  Source: laravel/framework

  • Laravel Version: 5.4.1
  • PHP Version: 7.0.4
  • node v6.9.4
  • npm v3.10.5

    Description:

npm commands are completely broken on windows (windows 7 in this case), whenever I run npm run dev I get the following error:

'node_modules' is not recognized as an internal or external command,
operable program or batch file.

node-debug.log

I tried

  "scripts": {
    "dev": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "hot": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "production": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },

It ran but without success:

> @ dev c:\wamp\www\web
> node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.co
nfig.js

path.js:7
    throw new TypeError('Path must be a string. Received ' + inspect(path));
    ^

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.parse (path.js:950:5)
    at new File (c:\wamp\www\web\node_modules\laravel-mix\src\File.js:14:30)
    at Object.module.exports.preprocess (c:\wamp\www\web\node_modules\laravel-mix\src\index.js:108:14)
    at Object.module.exports.sass (c:\wamp\www\web\node_modules\laravel-mix\src\index.js:84:27)
    at Object.<anonymous> (c:\wamp\www\web\webpack.mix.js:17:5)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Mix.initialize (c:\wamp\www\flores\node_modules\laravel-mix\src\Mix.js:38:9)
    at Object.<anonymous> (c:\wamp\www\flores\node_modules\laravel-mix\setup\webpack.config.js:18:5)
    at Module._compile (module.js:570:32)

Steps To Reproduce:

Run npm run dev command on windows.

Most helpful comment

@taylorotwell
go in package.json and instead of
"scripts": {
"dev": "node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "node_modules/cross-env/bin/cross-env.js NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"production": "node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},

put this:
"scripts": {
"dev": "cross-env NODE_ENV=development webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development webpack --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "cross-env NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"production": "cross-env NODE_ENV=production webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},

I hope I help :)

All 24 comments

These are the scripts as they are meant to be:

  "scripts": {
    "dev": "cross-env NODE_ENV=development webpack --progress --hide-modules",
    "watch": "cross-env NODE_ENV=development webpack --watch --progress --hide-modules",
    "hmr": "cross-env NODE_ENV=development webpack-dev-server --inline --hot",
    "production": "cross-env NODE_ENV=production webpack --progress --hide-modules"
  }

@PascaleBeier No.
Just installed the latest version. I'm pretty sure that's the package.json installed for Mac users.
Also, this is the master branch: https://github.com/laravel/laravel/blob/master/package.json

@Frondor Did you try these? Taken from laravel-mix.

Edit: also see issue #151

I have tried @PascaleBeier 's suggestion, but same issue.
Fresh installed Laravel 5.4.2 with npm 4.1.2, then npm install.
npm run production

npm-debug.txt

Looks like I may have to get my PC out of the closet :) ... can anyone confirm a working resolution that works on both mac and Windows?

@Frondor Please paste in your webpack.mix.js file.

@taylorotwell
go in package.json and instead of
"scripts": {
"dev": "node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "node_modules/cross-env/bin/cross-env.js NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"production": "node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},

put this:
"scripts": {
"dev": "cross-env NODE_ENV=development webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development webpack --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "cross-env NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"production": "cross-env NODE_ENV=production webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},

I hope I help :)

I dont know is this work for Mac but for me on Windows work

@bajro17 - But then it doesn't work if you're using Yarn. :/

I don't know than we need to find universal solution 馃槩

Just installed Laravel 5.4.3 on my windows machine and then ran

npm install

and then tried

npm run dev, npm run watch and it works perfectly fine for me.

Changes like cross-env NODE_ENV=development webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js don't work because it assumes you have cross-env added you your PATH environment variable.

Appending the node command to the string should do the trick, but the error I shared before is still there. Debug logs are pointing to c:\wamp\www\web\node_modules\laravel-mix\src\File.js:14:30.

I didn't try any other version than L5.4.1, I'll check the 5.4.3 once I get back in home.

That's why we need to see what your webpack.mix.js file looks like. I'm wondering if there's a method argument there that isn't correct.

@JeffreyWay everything is default, I didn't touch a single file.

const { mix } = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');

Win 8, node 7.4.0, npm 4.0.5 Laravel 5.4.3 everything works perfectly. Thanks for all the work put into this.

I updated Node from 5.x.x to 7.4.0 and then it works on Windows (same error before).

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

@Frondor - At this point, your question is specifically related to Laravel Mix. It doesn't have anything to do with the framework code. I'm going to port this question over there.

https://github.com/JeffreyWay/laravel-mix/issues/185

Same problem
win 10 64bits
wampserver php7

Solution:
Update windows npm with installer
https://nodejs.org/en/download/

You can solve this problem 100%
https://github.com/AttaUrRehman24/laravel-mix

In Windows (currently testing on Windows 10 X64), CD to your project root using the default CMD/Powershell(or press SHIFT+F10 to open extended options window and click on CMD) and run npm install then npm run development and finally npm run watch to watch your files. Goodluck!

Same problem when I run below

$ npm run dev

node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

'node_modules' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Tried cross-env and node but nothing is working for me.
I use integrated terminal MINGW64

My versions:

NPM - 5.6.0
Node - v8.11.2
Laravel - 5.4.36
Windows 8.1, 64-bit

My package.json:

{
"private": true,
"scripts": {
"dev": "node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "node_modules/cross-env/bin/cross-env.js NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"production": "node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.15.2",
"bootstrap-sass": "^3.3.7",
"jquery": "^3.1.0",
"laravel-mix": "^0.5.0",
"lodash": "^4.16.2",
"vue": "^2.0.1"
}
}

Please somebody help me with this. Thanks

Any updates here?
Scripts that work in mac and windows???

Maybe best to ask on the mix repo. I have a dev environment on Mac, Ubuntu and Windows and all work as expected.

Here is what worked for me on Win 10.

  "scripts": {
    "dev": "npm run env NODE_ENV=development&&webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "npm run env NODE_ENV=developmen&&webpack --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "hot": "npm run env NODE_ENV=development&&webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "production": "npm run env NODE_ENV=production&&webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mnpenner picture mnpenner  路  72Comments

Xerotherm1c picture Xerotherm1c  路  70Comments

mstnorris picture mstnorris  路  87Comments

Demers94 picture Demers94  路  88Comments

astr0naugh7 picture astr0naugh7  路  65Comments