编译资产时 node-sass 问题 - npm

Issue with node-sass while compiling asset - npm

我在 npm run prod

上收到此错误
npm run prod
> @ prod /opt/atlassian/pipelines/agent/build
> encore production
Running webpack ...
 ERROR  Failed to compile with 2 errors4:15:08 PM
 error  in ./web/assets/src/scss/styles.scss
Module build failed: 
$navbar-padding-horizontal:        floor(math.div($grid-gutter-width, 2)) !default;
                                            ^
      Invalid CSS after "...     floor(math": expected expression (e.g. 1px, bold), was ".div($grid-gutter-w"
      in /opt/atlassian/pipelines/agent/build/node_modules/bootstrap-sass/assets/stylesheets/bootstrap/_variables.scss (line 369, column 46)
 @ ./web/assets/src/scss/styles.scss 4:14-219
 error  in ./web/assets/src/scss/styles.scss

我已经进行了很多修复,其中之一是使用 sass 而不是我所做的 node-sass,但它会抛出此错误

  Error: Install node-sass to use enableSassLoader()
    yarn add node-sass --dev
  

如果我禁用 .enableSassLoader() 这个错误就会发生

 FIX  To load SASS files:
        1. Add Encore.enableSassLoader() to your webpack.config.js file.
        2. Install node-sass
              yarn add node-sass --dev

这是我的webpack.config.js

var Encore = require('@symfony/webpack-encore');
Encore
    .setOutputPath('web/assets/public')
    .setPublicPath('/assets/public')
    .cleanupOutputBeforeBuild()
    .enableBuildNotifications()
    .addEntry('js/scripts','./web/assets/src/js/scripts.js')
    .addEntry('js/video','./web/assets/src/js/video/video.js')
    .addEntry('js/registration','./web/assets/src/js/registration/registration-lookup.js')
    .addStyleEntry('styles', './web/assets/src/scss/styles.scss')
    .enableSassLoader(function(sassOptions) {
    }, {
         resolveUrlLoader: false
     })
    .enablePostCssLoader()
    .autoProvidejQuery()
    .enableSourceMaps(!Encore.isProduction())
;

这是我在 package.json

中的 devDependencies
"devDependencies": {
    "@symfony/webpack-encore": "^0.17.1",
    "autoprefixer": "^7.2.5",
    "bootstrap-sass": "^3.3.7",
    "cssnext": "^1.8.4",
    "jquery": "^3.6.0",
    "linting": "^1.0.0",
    "node-sass": "^4.7.2",
    "postcss-import": "^11.0.0",
    "postcss-loader": "^2.0.10",
    "sass-loader": "^6.0.6",
    "webpack-notifier": "^1.5.1"
  },

这是我的styles.scss

@import "imports/_variables.scss";

$icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/";
@import "~bootstrap-sass/assets/stylesheets/bootstrap";

看起来你一直在使用最新的 bootstrap-sass 但 webpack encore 不支持 math.div。

如果您删除“^3.3.7”中的 ^,它会将版本设置为 3.3.7,它不使用 math.div 函数,而是使用“/”进行除法,这应该仍然有效.

您应该考虑升级 webpack encore,但这可能(不容易)实现,具体取决于项目。