New*_*lar 7 sass stylelint angular
我今天有点失落。我想将 Stylelint 添加到我的 Angular 项目中,所以我运行了
npm install stylelint stylelint-config-standard --save-dev
安装 stylelint 和标准配置插件。然后我创建了一个.stylelintrc文件并向其中添加了以下代码:
{
"extends": ["stylelint-config-standard"],
"rules": {
"rule-empty-line-before": "always",
"comment-empty-line-before": "always"
}
}
Run Code Online (Sandbox Code Playgroud)
npx stylelint \"src/app/**/*.{css,scss}\"当从终端运行以下命令时,我注意到一切运行良好,但当我在 Angular 项目中使用 scss 时,我看到了一些错误。为了防止这些基于 scss 的错误,我决定引入该stylelint-config-standard-scss插件。我使用 npm 安装了它,然后将文件中的代码更新.stylelintrc为以下内容:
{
"extends": [
"stylelint-config-standard",
"stylelint-config-standard-scss"
],
"rules": {
"rule-empty-line-before": "always",
"comment-empty-line-before": "always"
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我运行命令时,npx stylelint \"src/app/**/*.{css,scss}\"出现以下错误!
TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (/Users/myuser/my-project/node_modules/postcss-scss/lib/nested-declaration.js:3:33)
at Module._compile (/Users/myuser/my-project/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (/Users/myuser/my-project/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at Object.<anonymous> (/Users/myuser/my-project/node_modules/postcss-scss/lib/scss-parser.js:4:25)
at Module._compile (/Users/myuser/my-project/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
Run Code Online (Sandbox Code Playgroud)
我不明白为什么会发生这种情况。该stylelint-config-standard-scss插件已下载并位于我的node_modules文件夹中。我的文件中没有语法错误.stylelintrc。我的节点版本很好(v14.18.1),我什至卸载并重新安装了所有 npm 软件包,但我得到了同样的错误?还有其他人遇到过这个问题并且能够解决它吗?
提前谢谢了。
Mik*_*Sav 13
我遇到了这个问题,我设法通过在 package.json 文件中添加 postcss 作为开发依赖项来解决此问题,例如:
"devDependencies": {
"postcss": "^8.4.13"
}
Run Code Online (Sandbox Code Playgroud)