运行“ npm run dev”后如何修复错误

时间:2019-04-10 09:05:08

标签: php laravel-5 npm

当我不得不在命令行中运行命令“ npm run dev ”时,我遵循了Laracast系列“ Laravel 5.7 From Scratch”中的Laravel教程。这产生了多个错误,我在下面包括了。

我搜索了确切的错误消息并尝试了建议的所有内容。

制作Laracast的JeffreyWay提出以下建议:

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

然后我在其他地方读到我应该尝试使用 npm install --save 一个接一个地安装依赖项,然后再次运行npm install,但这仍然无济于事。

有用的信息(如果有帮助的话):
Linux版本:Debian GNU / Linux 8.11(jessie)
PHP版本:PHP 7.1.27
NPM版本:5.1.0

运行 npm run dev 后收到的错误消息如下:

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

 98% after emitting SizeLimitsPlugin                                            

 ERROR  Failed to compile with 2 errors                                                                                                                                                                 10:41:15 AM

 error  in ./resources/sass/app.scss

Module build failed (from ./node_modules/css-loader/index.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/lib/loader.js):

@import '/myfirstsite/node_modules/bulma/sass/utilities/_all.sass'
       ^
      Can't find stylesheet to import.
  ╷
7 │ @import '/myfirstsite/node_modules/bulma/sass/utilities/_all.sass'
  │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  resources/sass/bulma.sass 7:9  @import
  stdin 10:9                     root stylesheet
      in /srv/htdocs/projects/frameworks/laravel/myfirstsite/resources/sass/bulma.sass (line 7, column 9)
    at runLoaders (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/webpack/lib/NormalModule.js:301:20)
    at /srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/loader-runner/lib/LoaderRunner.js:367:11
    at /srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/loader-runner/lib/LoaderRunner.js:233:18
    at context.callback (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at render (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass-loader/lib/loader.js:52:13)
    at Function.$2 (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:24382:48)
    at wO.$2 (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:15310:15)
    at uT.vr (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:9042:42)
    at uT.vq (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:9044:32)
    at iz.uD (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8392:46)
    at us.$0 (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8534:7)
    at Object.eG (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:1512:80)
    at ad.ba (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8455:3)
    at iN.ba (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8385:25)
    at iN.cv (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8372:6)
    at py.cv (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8162:35)
    at Object.m (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:1383:19)
    at /srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:5070:51
    at xe.a (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:1394:71)
    at xe.$2 (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8177:23)
    at vR.$2 (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8172:25)
    at uT.vr (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:9042:42)
    at uT.vq (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:9044:32)
    at iz.uD (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8392:46)
    at us.$0 (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8534:7)
    at Object.eG (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:1512:80)
    at ad.ba (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8455:3)
    at iN.ba (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8385:25)
    at iN.cv (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8372:6)
    at Object.eval (eval at CK (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:648:15), <anonymous>:3:37)
    at uT.vr (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:9042:42)
    at uT.vq (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:9044:32)
    at iz.uD (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8392:46)
    at us.$0 (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8534:7)
    at Object.eG (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:1512:80)
    at ad.ba (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8455:3)

 error  in ./resources/sass/app.scss

Module build failed (from ./node_modules/sass-loader/lib/loader.js):

@import '/myfirstsite/node_modules/bulma/sass/utilities/_all.sass'
       ^
      Can't find stylesheet to import.
  ╷
7 │ @import '/myfirstsite/node_modules/bulma/sass/utilities/_all.sass'
  │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  resources/sass/bulma.sass 7:9  @import
  stdin 10:9                     root stylesheet
      in /srv/htdocs/projects/frameworks/laravel/myfirstsite/resources/sass/bulma.sass (line 7, column 9)

 @ ./resources/sass/app.scss 2:14-255

     Asset      Size   Chunks             Chunk Names
/js/app.js  1.74 MiB  /js/app  [emitted]  /js/app

ERROR in ./resources/sass/app.scss
Module build failed (from ./node_modules/css-loader/index.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/lib/loader.js):

@import '/myfirstsite/node_modules/bulma/sass/utilities/_all.sass'
       ^
      Can't find stylesheet to import.
  ╷
7 │ @import '/myfirstsite/node_modules/bulma/sass/utilities/_all.sass'
  │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  resources/sass/bulma.sass 7:9  @import
  stdin 10:9                     root stylesheet
      in /srv/htdocs/projects/frameworks/laravel/myfirstsite/resources/sass/bulma.sass (line 7, column 9)
    at runLoaders (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/webpack/lib/NormalModule.js:301:20)
    at /srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/loader-runner/lib/LoaderRunner.js:367:11
    at /srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/loader-runner/lib/LoaderRunner.js:233:18
    at context.callback (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at render (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass-loader/lib/loader.js:52:13)
    at Function.$2 (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:24382:48)
    at wO.$2 (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:15310:15)
    at uT.vr (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:9042:42)
    at uT.vq (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:9044:32)
    at iz.uD (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8392:46)
    at us.$0 (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8534:7)
    at Object.eG (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:1512:80)
    at ad.ba (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8455:3)
    at iN.ba (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8385:25)
    at iN.cv (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8372:6)
    at py.cv (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8162:35)
    at Object.m (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:1383:19)
    at /srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:5070:51
    at xe.a (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:1394:71)
    at xe.$2 (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8177:23)
    at vR.$2 (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8172:25)
    at uT.vr (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:9042:42)
    at uT.vq (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:9044:32)
    at iz.uD (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8392:46)
    at us.$0 (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8534:7)
    at Object.eG (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:1512:80)
    at ad.ba (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8455:3)
    at iN.ba (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8385:25)
    at iN.cv (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8372:6)
    at Object.eval (eval at CK (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:648:15), <anonymous>:3:37)
    at uT.vr (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:9042:42)
    at uT.vq (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:9044:32)
    at iz.uD (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8392:46)
    at us.$0 (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8534:7)
    at Object.eG (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:1512:80)
    at ad.ba (/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/sass/sass.dart.js:8455:3)
 @ ./resources/sass/app.scss

ERROR in ./resources/sass/app.scss (./node_modules/css-loader??ref--5-2!./node_modules/postcss-loader/src??postcss0!./node_modules/resolve-url-loader??ref--5-4!./node_modules/sass-loader/lib/loader.js??ref--5-5!./resources/sass/app.scss)
Module build failed (from ./node_modules/sass-loader/lib/loader.js):

@import '/myfirstsite/node_modules/bulma/sass/utilities/_all.sass'
       ^
      Can't find stylesheet to import.
  ╷
7 │ @import '/myfirstsite/node_modules/bulma/sass/utilities/_all.sass'
  │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  resources/sass/bulma.sass 7:9  @import
  stdin 10:9                     root stylesheet
      in /srv/htdocs/projects/frameworks/laravel/myfirstsite/resources/sass/bulma.sass (line 7, column 9)
 @ ./resources/sass/app.scss 2:14-255
npm ERR! code ELIFECYCLE
npm ERR! errno 2
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 2
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!     /root/.npm/_logs/2019-04-10T08_41_15_277Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 2
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!     /root/.npm/_logs/2019-04-10T08_41_15_294Z-debug.log

第一个错误表明“ ./resources/sass/app.scss”中存在错误,但我找不到错误,并且编辑器未显示错误。 app.scss的内容是:

// Fonts
@import url('https://fonts.googleapis.com/css?family=Nunito');

// Variables
@import 'variables';

// Bootstrap
//@import '/myfirstsite/bootstrap/scss/bootstrap';
@import 'bulma.sass';

.navbar-laravel {
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

第二个错误说它找不到要导入的样式表,但是给出的路径是正确的。错误中的路径是:“ / myfirstsite / node_modules / bulma / sass / utilities / _all.sass”。

我在命令行中进行了检查,路径为: /srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/bulma/sass/utilities/_all.sass,这是正确的。

日志文件的详细信息如下:

0 info it worked if it ends with ok
1 verbose cli [ '/root/.nvm/versions/node/v11.10.1/bin/node',
1 verbose cli   '/root/.nvm/versions/node/v11.10.1/bin/npm',
1 verbose cli   'run',
1 verbose cli   'development' ]
2 info using npm@5.1.0
3 info using node@v11.10.1
4 verbose run-script [ 'predevelopment', 'development', 'postdevelopment' ]
5 info lifecycle @~predevelopment: @
6 info lifecycle @~development: @
7 verbose lifecycle @~development: unsafe-perm in lifecycle true
8 verbose lifecycle @~development: PATH: /root/.nvm/versions/node/v11.10.1/lib/node_modules/npm/bin/node-gyp-bin:/srv/htdocs/projects/frameworks/laravel/myfirstsite/node_modules/.bin:/root/.nvm/versions/node/v1$
9 verbose lifecycle @~development: CWD: /srv/htdocs/projects/frameworks/laravel/myfirstsite
10 silly lifecycle @~development: Args: [ '-c',
10 silly lifecycle   'cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js' ]
11 silly lifecycle @~development: Returned: code: 2  signal: null
12 info lifecycle @~development: Failed to exec development script
13 verbose stack Error: @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
13 verbose stack Exit status 2
13 verbose stack     at EventEmitter.<anonymous> (/root/.nvm/versions/node/v11.10.1/lib/node_modules/npm/lib/utils/lifecycle.js:289:16)
13 verbose stack     at EventEmitter.emit (events.js:197:13)
13 verbose stack     at ChildProcess.<anonymous> (/root/.nvm/versions/node/v11.10.1/lib/node_modules/npm/lib/utils/spawn.js:40:14)
13 verbose stack     at ChildProcess.emit (events.js:197:13)
13 verbose stack     at maybeClose (internal/child_process.js:984:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
14 verbose pkgid @
15 verbose cwd /srv/htdocs/projects/frameworks/laravel/myfirstsite
16 verbose Linux 3.16.0-7-amd64
17 verbose argv "/root/.nvm/versions/node/v11.10.1/bin/node" "/root/.nvm/versions/node/v11.10.1/bin/npm" "run" "development"
18 verbose node v11.10.1
19 verbose npm  v5.1.0
20 error code ELIFECYCLE
21 error errno 2
22 error @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
22 error Exit status 2
23 error Failed at the @ development script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]

package.json文件的内容如下:

{
    "private": true,
    "scripts": {
        "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",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development 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_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.18.0",
        "babel-loader": "^8.0.5",
        "bulma": "^0.7.4",
        "bulma-extensions": "^4.1.1",
        "cross-env": "^5.2.0",
        "jquery": "^3.3.1",
        "laravel-mix": "^4.0.15",
        "lodash": "^4.17.11",
        "npm-install-webpack-plugin": "^4.0.5",
        "popper.js": "^1.15.0",
        "resolve-url-loader": "^2.3.2",
        "sass": "^1.18.0",
        "sass-loader": "^7.1.0",
        "vue": "^2.6.10",
        "vue-loader": "^15.7.0",
        "vue-template-compiler": "^2.6.10",
        "webpack": "^4.29.6"
    }
}

请问有人能提供为什么的信息吗?

这是我在这里的第一篇文章,因此,如果您需要任何更多信息,请告诉我,我将包括在内。

谢谢。

1 个答案:

答案 0 :(得分:0)

我认为您以错误的方式包括了您的布尔玛。代替使用直接路径,将~用作节点模块路径。

例如,我正在这样导入

@import "~bulma/bulma";

这将使用node_modules/bulma/bulma.sass中的bulma.sass文件。