angular - stylelint 在引入 stylelint-config-standard-scss 时给出错误 "Class extends value undefined is not a constructor or null"

标签 angular sass stylelint

我今天有点不知所措。我想将 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"
  }
}

当从终端运行以下命令时 npx stylelint\"src/app/**/*.{css,scss}\" 我注意到一切正常,但因为我在中使用 scss在我的 Angular 项目中,我看到了一些错误。为了防止这些基于 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"
  }
}

现在,当我运行命令 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)

我不明白为什么会这样。 stylelint-config-standard-scss 插件已下载并位于我的 node_modules 文件夹中。我的 .stylelintrc 文件中没有语法错误。我的节点版本很好(v14.18.1),我什至卸载并重新安装了所有 npm 包,但我得到了同样的错误?有没有其他人遇到过这个问题并且能够解决它?

非常感谢。

最佳答案

我有这个问题,我设法通过在 package.json 文件中添加 postcss 作为开发依赖来解决这个问题,例如:

"devDependencies": {
   "postcss": "^8.4.13"
}

关于angular - stylelint 在引入 stylelint-config-standard-scss 时给出错误 "Class extends value undefined is not a constructor or null",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72272219/

相关文章:

css - 驼峰式 BEM 的正则表达式

angular - 如何以 Angular 6 显示微调器

Angular 静态 Base URl 和 useHash=True 的路由

Angular2 Observable 绑定(bind)不正确

html - CSS BEM - SVG 类

css - Prepros:观看所有文件但只编译主要文件

angular - Firebase实时数据库中有 "Multi-Path Push"这样的东西吗?

html - 页面背景为 90% 白色和 10% 缩放图像

stylelint - 无法在 stylelint 中将 block-no-empty 设置为 false

gruntjs - stylelint-selector-bem-pattern BEM linter 不起作用