import css 报错:Module build failed: Error: No PostCSS Config found in: ...

本文讲述了在Vue项目中遇到import.css报错,通过新建.postcssrc.js配置文件并设置相关插件,解决路径查找问题的过程。关键步骤包括引入postcss-plugins和配置文件编写。

发生原因:在main.js 文件通过import引入.css文件时 报错,找不到文件。路径和引入方法都是正确的

完整错误:

Module build failed: Error: No PostCSS Config found in: D:\vuetest\src
    at D:\vuetest\node_modules\postcss-load-config\src\index.js:55:15

解决办法:

由报错信息 at D:\vuetest\node_modules\postcss-load-config\src\index.js:55:15 可知应该是配置文件有问题。由此我对比可以正常引入 css文件的项目可知,根目录下缺少了 文件 .postcssrc.js。不上文件即可,项目根目录新建.postcssrc.js 文件,原本文件内容如下:

// https://github.com/michael-ciniawsky/postcss-load-config

module.exports = {
  "plugins": {
    "postcss-import": {},
    "postcss-url": {},
    // to edit target browsers: use "browserslist" field in package.json
    "autoprefixer": {}
  }
}

引入CSS文件

第一种在main.js 中引入:(全局)

import '对应的文件路径.css'

第二种在某个组件:(局部)

在 style 样式中引入

<style>
    @import '对应的文件路径.css'
</style>

或者

<style src="对应的文件路径.css">
</style>

如果需要局部使用,style 属性 加上 scoped
<style scoped src="对应的文件路径.css">
</style>

 

前端项目的index.css文件中有@unocss preflights; @unocss default; 这个 运行项目后报错Failed to compile, check the errors for troubleshooting. File: C:\Users\Lyun\Desktop\react-antd-admin-pro-main\src\index.css:1:1 × Module build failed: ╰─▶ × TypeError: Cannot read properties of undefined (reading '__esModule') │ at handleExports (C:\Users\Lyun\Desktop\react-antd-admin-pro-main\node_modules\@rspack\core\dist\cssExtractLoader.js:170:40) │ at C:\Users\Lyun\Desktop\react-antd-admin-pro-main\node_modules\@rspack\core\dist\cssExtractLoader.js:264:7 │ at C:\Users\Lyun\Desktop\react-antd-admin-pro-main\node_modules\@rspack\core\dist\index.js:6301:13 @ ./src/index.tsx File: C:\Users\Lyun\Desktop\react-antd-admin-pro-main\src\index.css:1:1 × Module build failed: ╰─▶ × Error: UnoCSS config not found: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:' │ at plugin (file:///C:/Users/Lyun/Desktop/react-antd-admin-pro-main/node_modules/@unocss/postcss/dist/esm.mjs:198:13) │ at async plugins (C:\Users\Lyun\Desktop\react-antd-admin-pro-main\node_modules\@unocss\postcss\dist\index.cjs:11:16) │ at async LazyResult.runAsync (C:\Users\Lyun\Desktop\react-antd-admin-pro-main\node_modules\@rsbuild\core\compiled\postcss\index.js:1088:17) │ at async Object.loader (C:\Users\Lyun\Desktop\react-antd-admin-pro-main\node_modules\@rsbuild\core\compiled\postcss-loader\index.js:99:20)
08-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值