【问题标题】:Error: File to import not found or unreadable: node_modules/bootstrap/错误:找不到或无法读取要导入的文件:node_modules/bootstrap/
【发布时间】:2020-11-15 16:33:21
【问题描述】:

当我尝试导入其他 scss 文件时,WebCompiler 出现了一个奇怪的问题。我的团队中没有一个同事有这个问题,我们不知道是什么原因造成的,所以我希望你能帮助我。

我们有这样的导入:

@import "node_modules/bootstrap/scss/bootstrap";

在多个文件中,但 VS 2019 在最新更新后抛出了这个异常:

Error: File to import not found or unreadable: node_modules/...

我尝试过:

  1. 重新安装 WebCompiler。
  2. 让 Visual Studio 重新创建 %localappdata%\temp\WebCompiler1.X 文件夹(我有 2 个文件夹 WebCompiler 出于某种原因,每次我让 VS 重新创建 它们都会生成它们。)

它在错误消息中提到的文件肯定存在,所以我认为它根本无法读取它们,但我不知道为什么。

【问题讨论】:

  • 这方面有什么更新吗?

标签: sass less visual-studio-2019 web-compiler


【解决方案1】:

我有同样的错误。但是我可以通过将“node_modules”添加到我的 includePath 到我的 compilerconfig.json.defaults 文件中来修复它 - 在 sass 部分:

"sass": {
  ...
  "includePath": "node_modules",
  ...
}

然后您可以从导入路径中删除 node_modules 路径。即:

@import "carbon-components/scss/globals/scss/_css--reset";

如果您没有默认文件,您也可以在 compilerconfig.json 中按文件执行:

[
  {
     "outputFile": "Scss/Carbon.css",
     "inputFile": "Scss/Carbon.scss",
     "options": {
         "includePath": "node_modules"
      }
  }
]

我希望它对你有用:)

【讨论】:

  • 谢谢你 - 这很好。
猜你喜欢
  • 2017-10-04
  • 1970-01-01
  • 2018-07-04
  • 2017-06-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-26
  • 1970-01-01
  • 2018-05-05
相关资源
最近更新 更多