2

I have installed nodejs on my ubuntu16.04 . But I can't run this. When I write a command npm run dev it shows the following error:


> @ dev /var/www/html/laravel
> 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

module.js:472
    throw err;
    ^

Error: Cannot find module '/var/www/html/laravel/node_modules/cross-env/bin/cross-env.js'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:425:7)
    at startup (bootstrap_node.js:146:9)
    at bootstrap_node.js:540:3

npm ERR! Linux 4.4.0-66-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "dev"
npm ERR! node v7.7.3
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! @ 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`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ dev script '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'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the  package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     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
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs 
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls 
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /var/www/html/laravel/npm-debug.log

Here I have also installed npm-debug.log using the below command but still I'm facing this problem

npm install --save debug-logenter image description here

3 Answers3

0

Using npm install installs the module into the current directory only (in a subdirectory called node_modules).

This guide was very helpful to me as well: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-16-04

solidak
  • 5,033
  • 3
  • 31
  • 33
0

It's a problem in the package.json "scripts" configuration. Either replace the "scripts" section in your package.json file with the following:

"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"

Then re-install the node modules.

Or, as another option, follow Jeffrey Way's advice found at the bottom of the following cross-env issue page.

alaric
  • 987
  • 5
  • 10
0

I had same problem when upgraded cross-env package.

Previously it was:  

node node_modules/cross-env/bin/cross-env.js

I've fixed package.json file and made the path like this:

node_modules/cross-env/dist/bin/cross-env.js

And to not happen same issue again I've just set version of cross-env in dependencies to be strict.

num8er
  • 18,604
  • 3
  • 43
  • 57