nextjs中(目前我是12.x),默认只能引入xxx.module.css,但有些三方组件中会存在引入xx.css的情况, 比如我目前用到的antd-mobile,会出现如下错误:
./node_modules/antd-mobile/es/components/action-sheet/action-sheet.css
Global CSS
be imported from within
Read more: https://nextjs.org/docs/messages/css-npm
Location:
Module build failed: Error: Final loader (./node_modules/next/dist/build/webpack/loaders/error-loader.js) didn’t return a Buffer or String
需要加如下代码处理:
// next.config.js
const withTM = require('next-transpile-modules')([
'antd-mobile',
// ...你的一些其他引用了.css文件的三方库
]);
const nextConfig = withTM({
// 其他next配置...
})
module.exports = nextConfig
解决办法参考: antd-mobile ssr渲染