Webpack:沒有加載器來處理 SCSS 是輸入存在 (Webpack: no loader to handle the SCSS is input is present)


問題描述

Webpack:沒有加載器來處理 SCSS 是輸入存在 (Webpack: no loader to handle the SCSS is input is present)

我已經安裝了 Webpack 5(版本 5.37.0)並且想要將 SASS 文件編譯為獨立的 CSS 文件。我收到以下錯誤:

 $ npx webpack 資產 index.js 555 KiB [與 emit 相比](名稱:main)運行時模塊 1.25 KiB 6 個模塊可緩存模塊 532 KiB ./src/index.js 238 bytes [built] [code generated] ./node_modules/lodash/lodash.js 531 KiB [built] [code generated] ./src/style.scss 78 bytes [built] [code generated] [1 error] ./ 中的錯誤src/style.scss 1:11 模塊解析失敗:意外令牌 (1:11) 您可能需要適當的加載程序來處理此文件類型,目前沒有配置加載程序來處理此文件。見 https://webpack.js.org/concepts#loaders > $body‑color: red; | | 正文 {@./src/index.js 2:0‑22 

我知道這意味著不存在處理 SCSS 輸入的加載程序。

當我用谷歌搜索這個錯誤時,我找到了很多答案,但它們不起作用。我認為它們適用於舊版本的 Webpack。

下面是我的整個 webpack.config.js

 const path = require("path") ; const MiniCssExtractPlugin = require('mini‑css‑extract‑plugin') const isDevelopment = process.env.NODE_ENV === 'development' module.exports = { entry: "./src/index.js", mode: "development ",輸出:{ 文件名:"index.js",路徑:path.resolve(__dirname, "dist") },模塊:{ 規則:[ { test: /\.module\.s(a|c)ss$ /, 利用:[ MiniCssExtractPlugin.loader, "css‑loader", { loader: "sass‑loader", options: { // 首選 `dart‑sass` 實現: require("sass"), }, }, ], }, ], }, plugins: [ new MiniCssExtractPlugin({ filename: isDevelopment ? '[name].css' : '[name].[hash].css', chunkFilename: isDevelopment ? '[id].css' : '[id]. [哈希].css' }) ], }; 

感謝幫助調試這個。

options: { // 首選`dart‑sass` implementation: require("sass"), }, }, ], }, ], }, plugins: [ new MiniCssExtractPlugin({ filename: isDevelopment ? '[name].css' : '[name].[hash].css', chunkFilename: isDevelopment ? '[id].css' : '[id].[hash].css' }) ], };

感謝幫助調試這個。

options: { // 首選`dart‑sass` implementation: require("sass"), }, }, ], }, ], }, plugins: [ new MiniCssExtractPlugin({ filename: isDevelopment ? '[name].css' : '[name].[hash].css', chunkFilename: isDevelopment ? '[id].css' : '[id].[hash].css' }) ], };

感謝幫助調試這個。

[新的MiniCssExtractPlugin({文件名:isDevelopment?'[name].css':'[name].[hash].css',chunkFilename:isDevelopment?'[id].css':'[id].[hash]。 css' }) ], };

感謝幫助調試這個。

[新的MiniCssExtractPlugin({文件名:isDevelopment?'[name].css':'[name].[hash].css',chunkFilename:isDevelopment?'[id].css':'[id].[hash]。 css' }) ], };

感謝幫助調試這個。


參考解法

方法 1:

I've found the error. Replacing:

test: /\.module\.s(a|c)ss$/,

with

 test: /\.s(a|c)ss$/,

fixes it.

I am still pretty new to Webpack, and cutting and pasting from tutorials on the web has its hazards.

(by Free RadicalFree Radical)

參考文件

  1. Webpack: no loader to handle the SCSS is input is present (CC BY‑SA 2.5/3.0/4.0)

#Webpack #css #sass-loader #SASS






相關問題

Babel 6 轉換運行時:$export 不是函數 (Babel 6 transform-runtime: $export is not a function)

Webpack 和 Sass 正確處理 background: url() 圖像,但是在與 webpack-dev-server 一起使用時找不到它 (Webpack and Sass correctly processes background: url() image but then it's not found when used with webpack-dev-server)

Babel 和 ES6 出現意外的“Uncaught TypeError: XXX is not a constructor”錯誤 (Unexpected "Uncaught TypeError: XXX is not a constructor" errors with Babel and ES6)

Webpack bundle ENOENT:沒有這樣的文件或目錄 fs.readdirSync (Webpack bundle ENOENT: no such file or directory fs.readdirSync)

有沒有辦法通過替換一些資產和組件從單個應用程序構建多個應用程序? (Is there a way to build multiple apps from single one with replacing some assets and components?)

Babel 7 不能正確轉換 index.js (Babel 7 don't convert index.js properly)

使用 Yarn 安裝的軟件包開始出現 sweetalert2 之類的錯誤 (packages installed with Yarn start to give error like sweetalert2)

找不到模塊 RecipeStyle.css (cannot find module RecipeStyle.css)

用於文件、子文件的 Webpack 加載器並將它們添加到跟踪列表 (Webpack loader for file, subfiles and add them to tracking list)

Webpack:沒有加載器來處理 SCSS 是輸入存在 (Webpack: no loader to handle the SCSS is input is present)

Webpack 在初始構建後不構建捆綁包 (Webpack not building bundle after initial build)

從其他機器訪問 webpack DevServer 子 URL 時出現 ERR_SSL_PROTOCOL_ERROR (ERR_SSL_PROTOCOL_ERROR when accessing webpack DevServer sub-URLs from a different machine)







留言討論