我尝试在终端中执行npm run dev命令时出现Npm错误

时间:2018-09-18 09:09:03

标签: node.js ubuntu npm npm-install

我很新鲜,就在四个月前开始了我的职业生涯。

我正在使用Ubuntu和laravel开发我的项目。我正在尝试编译一个.js文件,为此我在项目文件夹中安装了npm和bower。安装顺利且完成。

但是在执行“ npm run dev”时,出现以下错误。

我执行了以下命令:

sudo n最新  错误是:

npm run dev

> npm run development


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

events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: spawn node_modules/webpack/bin/webpack.js ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:232:19)
    at onErrorNT (internal/child_process.js:407:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:279:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:696:3)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:238:12)
    at onErrorNT (internal/child_process.js:407:16)
    [... lines matching original stack trace ...]
    at bootstrapNodeJSCore (internal/bootstrap/node.js:696:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ development: `cross-env 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 @ development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vidya/.npm/_logs/2018-09-18T09_27_31_491Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `npm run development`
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vidya/.npm/_logs/2018-09-18T09_27_31_546Z-debug.log

在此方面的任何帮助将不胜感激。

NPM version:6.4.1
bower version: 1.8.4
ubuntu version:UBUNTU 16.04 LTS

3 个答案:

答案 0 :(得分:1)

复制步骤:

清洁Laravel安装( 作曲家创建项目laravel / laravel网络界面)

run: composer install
run: npm install
run: npm run dev

请按照以下步骤操作:

rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
npm install

这里是link

答案 1 :(得分:0)

我在根目录中使用了以下代码,问题已得到解决。

sudo npm install -g PACKAGE-NAME --unsafe-perm=false --allow-root

我在下面用来安装所有软件包。

sudo npm install -g --unsafe-perm=false --allow-root 

Npm现在工作正常。

感谢您的所有帮助。

答案 2 :(得分:0)

应该将webpack-dev-server降级为:

npm install --save-dev webpack-dev-server@2.9.7