Vue uses style loader to add CSS style to Dom and reports an error
ERROR in ./src/css/normal.css
Module build failed: CssSyntaxError
(1:1) Unknown word
> 1 | var content = require("!!./normal.css");
| ^
2 |
3 | if (typeof content === 'string') {
@ ./src/main.js 11:0-27
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `webpack`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
The loader sequence you configured in the webpack.config.js file may be wrong
original code
const path=require('path')
module.exports={
entry: './src/main.js',
output: {
path:path.resolve(__dirname,'dist'),
filename:'bundle.js'
},
module: {
rules: [
{
test: /\.css$/,
use: ['css-loader','style-loader']
},
]
}
}
Code after modification
const path=require('path')
module.exports={
entry: './src/main.js',
output: {
path:path.resolve(__dirname,'dist'),
filename:'bundle.js'
},
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader','css-loader']
},
]
}
}
This is because when multiple loaders are configured, the program is read from right to left
Read More:
- [Solved] Module build failed TypeError this.getOptions is not a function at Object.loader
- [Solved] Uniapp project use vant icon Error: (module build failed from./node_modules/postcss loader/SRC/index)
- [Solved] Vue Error: Module build failed Error Node Sass version 6.0.1 is incompatible with ^4.0.0.
- [Solved] Module build failed: Error: Vue packages version mismatch
- The vue3 project Error: Cannot find module’vue-loader-v16/package.json’
- [Solved] Vue Error: Module build failed: Error: No PostCSS Config found in
- [Solved] webpack Package Error: TypeError: this.getOptions is not a function style-loader
- [Solved] VUE npm install Error: Module build failed: Error: ENOENT: no such file or directory, scandir
- [Solved] Vue Project Error: Module build failed: Error: Missing binding
- [Solved] Vue Install loader Error: Syntax Error: Error: Cannot find module ‘less‘
- [Solved] Vue binding dynamic inline style Error: transform:rotate()
- Module build failed: Error: Couldn’t find preset “es2015” relative to directory
- [Solved] This.getoptions is not a function when installing sass loader and less loader
- [Solved] ERROR Error: Cannot find module ‘vue-loader-v16/package.json‘
- [Vue Run Error] Module build failed: Error: Couldn‘t resolve parser “babylon“
- Vue installs sass loader directly, and node sass reports an error
- [Solved] Vue Route Error: Uncaught TypeError: (0 , vue__WEBPACK_IMPORTED_MODULE_42__.defineComponent) is not a function
- Solution to build error in Vue project (error in static/JS)/vendor.xxxxx.js from UglifyJs)
- vue.config.js build Package UglifyJsPlugin to clear console and print console.log Error: `warnings` is not a supported option
- [Solved] vue3vite Error: Failed to resolve import “@vue/server-renderer from “src\App.vue“. Does the file exist