Node-sass无法编译

问题描述

尝试使用node-sass从scss创建CSS文件。 我的package.json:

 {
  "name": "hello-webpack","version": "1.0.0","description": "","main": "index.js","scripts": {
    "test": "echo \"Error: no test specified\" && exit 1","scss": "node-sass -watch scss -o css"
  },"author": "","license": "ISC","devDependencies": {
    "sass": "^1.26.10","sass-loader": "^9.0.3","webpack": "^4.44.1","webpack-cli": "^3.3.11"
  },"dependencies": {
    "node-sass": "^4.14.1"
  }
}

但是当我尝试npm运行scss时,我看到此错误

> node-sass -watch scss -o css

internal/validators.js:120
    throw new ERR_INVALID_ARG_TYPE(name,'string',value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:120:11)
    at Object.extname (path.js:1229:5)
    at getoptions (/Users/mac/Documents/Website/node_modules/node-sass/bin/node-sass:192:40)
    at Object.<anonymous> (/Users/mac/Documents/Website/node_modules/node-sass/bin/node-sass:376:15)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'ERR_INVALID_ARG_TYPE'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hello-webpack@1.0.0 scss: `node-sass -watch scss -o css`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the hello-webpack@1.0.0 scss 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!     /Users/mac/.npm/_logs/2020-08-20T14_02_52_371Z-debug.log

路径出了什么问题?是的,我有目录scss和css,并且两者都有一些文件

解决方法

您正在使用完整的watch选项名称,该名称需要2个破折号。否则,在速记选项名称上使用1破折号。

node-sass scss --watch -o css

node-sass scss -wo css

https://www.npmjs.com/package/node-sass#command-line-interface

,

您感到困惑的是,向我们展示了您的package.json,但使用的是全局安装的node-sass npm模块

由于您已全局安装了节点萨斯,因此可以在以下任何位置使用该命令:

node-sass yourscss.sass > output_yourscss.css -watch

自然将路径传递到您的css文件,上述示例是从与我的 yourscss.sass 文件

相同的目录中调用的