gpt4 book ai didi

ruby-on-rails - 通过 webpacker 编译 js 导致 : SassError: expected "{"

转载 作者:行者123 更新时间:2023-12-04 12:34:27 49 4
gpt4 key购买 nike

我正在尝试使用 scss在我的 rails 应用程序中,由 webpacker 配置.每当我跑 rails webpacker:compile ,我收到以下错误:

ERROR in ./app/javascript/stylesheets/application.scss
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: expected "{".

1 │ import api from "!../../../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js";
│ ^

app/javascript/stylesheets/application.scss 1:95 root stylesheet
我在调试这个问题时遇到了麻烦,希望得到任何帮助。

依赖关系
rails: 6.1
webpacker: 6.0.0.pre1
@webpack-cli/serve
webpack: 5.11
webpack-cli: 4.2
webpack-dev-server: 3.11
package.json
{
"name": "ostor",
"private": true,
"dependencies": {
"@popperjs/core": "^2.6.0",
"@rails/actioncable": "^6.1.2-1",
"@rails/activestorage": "^6.1.2-1",
"@rails/ujs": "^6.1.2-1",
"@rails/webpacker": "^6.0.0-beta.5",
"autoprefixer": "^10.2.4",
"bootstrap": "^v5.0.0-beta2",
"css-loader": "^5.0.2",
"css-minimizer-webpack-plugin": "^1.2.0",
"d3": "^6.2.0",
"jquery": "^3.5.1",
"mini-css-extract-plugin": "^1.3.7",
"postcss": "^8.2.6",
"postcss-loader": "^5.0.0",
"sass": "^1.32.7",
"sass-loader": "^11.0.1",
"style-loader": "^2.0.0",
"turbolinks": "^5.2.0",
"webpack": "^5.11.0",
"webpack-cli": "^4.2.0"
},
"version": "0.1.0",
"devDependencies": {
"@webpack-cli/serve": "^1.3.0",
"webpack-dev-server": "^3.11.2"
},
"babel": {
"presets": [
"./node_modules/@rails/webpacker/package/babel/preset.js"
]
},
"browserslist": [
"defaults"
]
}
config/webpack/base.js :
const { webpackConfig, merge } = require('@rails/webpacker')

const customConfig = {
module: {
rules: [
{
test: /\.s[ac]ss$/i,
exclude: /node_modules/,
use: [
// Creates `style` nodes from JS strings
"style-loader",
// Translates CSS into CommonJS
"css-loader",
// Compiles Sass to CSS
"sass-loader",
],
},
],
},
}

module.exports = merge(webpackConfig, customConfig)
app/javascript/packs/application.js
import ActiveStorage from "@rails/activestorage";
import * as RailsUjs from "@rails/ujs";
import Turbolinks from "turbolinks";

ActiveStorage.start();
RailsUjs.start();
Turbolinks.start();

import "channels";
import "bootstrap";

import "../stylesheets/application.scss";

最佳答案

删除您为 SASS/SCSS 添加的自定义配置规则。当 Webpacker 6 检测到您安装了 css-loader、postcss-loader、mini-css-extract-plugin 等时,它会为您提供适当的 CSS 规则。

关于ruby-on-rails - 通过 webpacker 编译 js 导致 : SassError: expected "{",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66216033/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com