简体   繁体   中英

Using sass-lint within npm script leads to error

I'm putting together an app using angular-cli. I'm going to write my styles in SCSS and as such I want to have linting available for my SCSS files. Node-sass is already installed when using angular-cli to create an app and I've install sass-lint locally.

I can now run the linting command successfully from the command line:

./node_modules/.bin/sass-lint 'src/**/*.scss' -v -q

And this gives me a list of errors and warnings:

src/app/app.component.scss
  2:3   error    Expected `background-color`, found `color`                                     property-sort-order
  2:10  warning  Color 'red' should be written in its hexadecimal form #ff0000               no-color-keywords
  2:10  warning  Color literals such as 'red' should only be used in variable declarations   no-color-literals
  3:3   error    Expected `color`, found `background-color`                                  property-sort-order
  3:21  warning  Color 'blue' should be written in its hexadecimal form #0000ff              no-color-keywords
  3:21  warning  Color literals such as 'blue' should only be used in variable declarations  no-color-literals

However, when I add this comand as an NPM script in package.json it produces an error, even though it also gives me the result of the linting:

{
    ...
    "scripts": {
        "scsslint": "./node_modules/.bin/sass-lint 'src/**/*.scss' -v -q"
    }
    ...
}

Result output:

> starter@0.0.0 scsslint /home/brian/Projects/tutorials/angular2/starter
> sass-lint 'src/**/*.scss' -v -q


src/app/app.component.scss
  2:3   error    Expected `background-color`, found `color`                                  property-sort-order
  2:10  warning  Color 'red' should be written in its hexadecimal form #ff0000               no-color-keywords
  2:10  warning  Color literals such as 'red' should only be used in variable declarations   no-color-literals
  3:3   error    Expected `color`, found `background-color`                                  property-sort-order
  3:21  warning  Color 'blue' should be written in its hexadecimal form #0000ff              no-color-keywords
  3:21  warning  Color literals such as 'blue' should only be used in variable declarations  no-color-literals

✖ 6 problems (2 errors, 4 warnings)


npm ERR! Linux 4.4.0-64-generic
npm ERR! argv "/usr/local/bin/node" "/home/brian/.npm-packages/bin/npm" "run" "scsslint"
npm ERR! node v6.9.4
npm ERR! npm  v4.3.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! starter@0.0.0 scsslint: `sass-lint 'src/**/*.scss' -v -q`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the starter@0.0.0 scsslint script 'sass-lint 'src/**/*.scss' -v -q'.
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 starter package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     sass-lint 'src/**/*.scss' -v -q
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs starter
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls starter
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/brian/.npm/_logs/2017-03-14T11_52_04_406Z-debug.log

Here is the resulting log output from NPM:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli   '/home/brian/.npm-packages/bin/npm',
1 verbose cli   'run',
1 verbose cli   'scsslint' ]
2 info using npm@4.3.0
3 info using node@v6.9.4
4 verbose run-script [ 'prescsslint', 'scsslint', 'postscsslint' ]
5 info lifecycle starter@0.0.0~prescsslint: starter@0.0.0
6 silly lifecycle starter@0.0.0~prescsslint: no script for prescsslint, continuing
7 info lifecycle starter@0.0.0~scsslint: starter@0.0.0
8 verbose lifecycle starter@0.0.0~scsslint: unsafe-perm in lifecycle true
9 verbose lifecycle starter@0.0.0~scsslint: PATH: /home/brian/.npm-packages/lib/node_modules/npm/bin/node-gyp-bin:/home/brian/Projects/tutorials/angular2/starter/node_modules/.bin:/home/brian/.npm-packages/bin:/home/brian/bin:/home/brian/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
10 verbose lifecycle starter@0.0.0~scsslint: CWD: /home/brian/Projects/tutorials/angular2/starter
11 silly lifecycle starter@0.0.0~scsslint: Args: [ '-c', 'sass-lint \'src/**/*.scss\' -v -q' ]
12 silly lifecycle starter@0.0.0~scsslint: Returned: code: 1  signal: null
13 info lifecycle starter@0.0.0~scsslint: Failed to exec scsslint script
14 verbose stack Error: starter@0.0.0 scsslint: `sass-lint 'src/**/*.scss' -v -q`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/home/brian/.npm-packages/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:191:7)
14 verbose stack     at ChildProcess.<anonymous> (/home/brian/.npm-packages/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:191:7)
14 verbose stack     at maybeClose (internal/child_process.js:877:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid starter@0.0.0
16 verbose cwd /home/brian/Projects/tutorials/angular2/starter
17 error Linux 4.4.0-64-generic
18 error argv "/usr/local/bin/node" "/home/brian/.npm-packages/bin/npm" "run" "scsslint"
19 error node v6.9.4
20 error npm  v4.3.0
21 error code ELIFECYCLE
22 error errno 1
23 error starter@0.0.0 scsslint: `sass-lint 'src/**/*.scss' -v -q`
23 error Exit status 1
24 error Failed at the starter@0.0.0 scsslint script 'sass-lint 'src/**/*.scss' -v -q'.
24 error Make sure you have the latest version of node.js and npm installed.
24 error If you do, this is most likely a problem with the starter package,
24 error not with npm itself.
24 error Tell the author that this fails on your system:
24 error     sass-lint 'src/**/*.scss' -v -q
24 error You can get information on how to open an issue for this project with:
24 error     npm bugs starter
24 error Or if that isn't available, you can get their info via:
24 error     npm owner ls starter
24 error There is likely additional logging output above.
25 verbose exit [ 1, true ]

I can't work out how to find what is causing this error. Can anyone point me in the right direction?

The error was most likely triggered by the Sass linter errors captured in the code.

Every time this happens sass-lint sets the exit code to 1 (error) which, in turn, gets picked up by the Node.js environment - hence all these ERR log entries.

If you'd only had linter warnings , the exit code would have been 0 (or "success") and that issue would have not cropped up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM