npm SassError:找不到要导入的样式表,->@import '~@swimlane/ngx-datatable/themes/bootstrap. scss';

pexxcrt2  于 2022-11-14  发布在  Bootstrap
关注(0)|答案(1)|浏览(199)

我正在我的一个Angular项目中使用@swimlane/ngx-datatable,当我在本地系统上执行ng build --configuration=myconfig时,它没有任何错误地构建,甚至通过执行ng serve运行得很好。
问题是,当我尝试在Github Actions上运行相同的命令时,它失败了,并出现以下错误:

./src/styles.scss - Error: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Can't find stylesheet to import.
   ╷
13 │ @import '~@swimlane/ngx-datatable/themes/bootstrap.scss';
   │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   ╵
  src/styles.scss 13:9  root stylesheet
    at processResult (/home/runners/actions-runner/_work/ui/ui/node_modules/webpack/lib/NormalModule.js:713:19)
    at /home/runners/actions-runner/_work/ui/ui/node_modules/webpack/lib/NormalModule.js:819:5
    at /home/runners/actions-runner/_work/ui/ui/node_modules/loader-runner/lib/LoaderRunner.js:400:11
    at /home/runners/actions-runner/_work/ui/ui/node_modules/loader-runner/lib/LoaderRunner.js:252:18
    at context.callback (/home/runners/actions-runner/_work/ui/ui/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
    at Object.callback (/home/runners/actions-runner/_work/ui/ui/node_modules/sass-loader/dist/index.js:54:7)
    at Worker.<anonymous> (/home/runners/actions-runner/_work/ui/ui/node_modules/@angular-devkit/build-angular/src/sass/sass-service.js:134:25)
    at Worker.emit (node:events:513:28)
    at MessagePort.<anonymous> (node:internal/worker:236:53)
    at MessagePort.[nodejs.internal.kHybridDispatch] (node:internal/event_target:736:20)
Error: Process completed with exit code 1.

我已经在我的styles.scss文件中导入了datatable的所有scss文件,如下所示:

@import '~@swimlane/ngx-datatable/index.css';
@import '~@swimlane/ngx-datatable/themes/bootstrap.scss';
@import '~@swimlane/ngx-datatable/themes/material.scss';
@import '~@swimlane/ngx-datatable/themes/dark.scss';
@import '~@swimlane/ngx-datatable/assets/icons.css';

以下是我的Angular 配置:

"@swimlane/ngx-datatable": "^20.0.0",
---
---
"@angular-devkit/build-angular": "~12.2.7",
"@angular/cli": "~12.2.7",
"@angular/compiler-cli": "~12.2.0",
---
---
node version: 16.17.1

而且我可以在我的本地机器的node_modules中看到scss文件的路径。我该如何解决这个问题呢?提前感谢。:)

68bkxrlz

68bkxrlz1#

引导程序css是否包含在angular.json中?它应该看起来像这样:

"projects": {
  "your-project": {
    "architect": {
      "build": {
        "builder": "@angular-devkit/build-angular:browser",
          "options": {
          ...
          "styles": [
            "./node_modules/path/to/css/bootstrap.css",
            "src/styles.scss"
          ]
        }
      }
    }
  }
}

虽然这并不能真正解释为什么构建过程没有在本地失败。你确定你正在运行完全相同的命令吗?

相关问题