在使用nextjs创建一个ssr项目引入antd-mobile时出现报错
./node_modules/react-datepicker/dist/react-datepicker.css
Global CSS cannot be imported from within node_modules.
Read more: https://err.sh/next.js/css-npm
Location: node_modules/@edooking/ui/src/elements/DatePicker/DatePicker.tsx
我们直接根据文档安装就可以了antd-mobile
首先安装next-transpile-modules依赖:
npm install --save-dev next-transpile-modules
# or
yarn add -D next-transpile-modules
# or
pnpm add -D next-transpile-modules
然后在 next.config.js 中进行配置:
const withTM = require('next-transpile-modules')([
'antd-mobile',
]);
module.exports = withTM({
// 你项目中其他的 Next.js 配置
});