我无法在ubuntu16.04上运行nodejs

时间:2017-03-16 08:31:51

标签: node.js laravel npm npm-install laravel-5.4

我在ubuntu16.04上安装了nodejs。但我不能这样做。当我编写命令 npm run dev 时,它会显示以下错误:

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

在这里,我还使用以下命令安装了 npm-debug .log,但我仍然面临这个问题

  

npm install --save debug-log enter image description here

3 个答案:

答案 0 :(得分:0)

使用var results = store.query({ start: 0, count: 3 }); results.then(function (data) { // You can access the response data here results.total.then(function (total) { // You can access total here }); }); 仅将模块安装到当前目录中(在名为node_modules的子目录中)。

本指南对我也很有帮助:https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-16-04

答案 1 :(得分:0)

这是package.json“scripts”配置中的一个问题。使用以下内容替换package.json文件中的“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"

然后重新安装节点模块。

或者,作为另一种选择,请遵循以下cross-env issue page底部的Jeffrey Way的建议。

答案 2 :(得分:0)

升级的跨env包时遇到同样的问题。

以前是:

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

我已经修复了package.json文件并创建了这样的路径:

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

为了不再发生同样的问题,我只是将依赖关系中的cross-env版本设置为严格。