启动Next.js项目时出现模块缺失错误:找不到caniuse-lite相关模块
Next.js启动报错:Cannot find module 'caniuse-lite/data/features/css-unicode-bidi'
错误详情
启动Next.js项目时触发以下错误:
error - ./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[2].oneOf[8].use[1]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[2].oneOf[8].use[2]!./styles/globals.css Error: Cannot find module 'caniuse-lite/data/features/css-unicode-bidi'
对应的调用栈信息:
Require stack: - /home/ragil/Documents/study/framework/testing/node_modules/next/dist/compiled/postcss-preset-env/index.cjs - /home/ragil/Documents/study/framework/testing/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js - /home/ragil/Documents/study/framework/testing/node_modules/next/dist/build/webpack/config/blocks/css/index.js - /home/ragil/Documents/study/framework/testing/node_modules/next/dist/build/webpack/config/index.js - /home/ragil/Documents/study/framework/testing/node_modules/next/dist/build/webpack-config.js - /home/ragil/Documents/study/framework/testing/node_modules/next/dist/server/dev/hot-reloader.js - /home/ragil/Documents/study/framework/testing/node_modules/next/dist/server/dev/next-dev-server.js - /home/ragil/Documents/study/framework/testing/node_modules/next/dist/server/next.js - /home/ragil/Documents/study/framework/testing/node_modules/next/dist/server/lib/start-server.js - /home/ragil/Documents/study/framework/testing/node_modules/next/dist/cli/next-dev.js - /home/ragil/Documents/study/framework/testing/node_modules/next/dist/lib/commands.js - /home/ragil/Documents/study/framework/testing/node_modules/next/dist/bin/next
注:已尝试通过npm和yarn重新安装Next.js,问题未解决。
解决步骤
- 单独安装缺失的
caniuse-lite包:- npm命令:
npm install caniuse-lite --save-dev - yarn命令:
yarn add caniuse-lite --dev
- npm命令:
- 若上述方法无效,清理依赖缓存并重装所有依赖:
- 使用npm:
- 执行
npm cache clean --force清理缓存 - 删除项目根目录下的
node_modules文件夹和package-lock.json文件 - 执行
npm install重装依赖
- 执行
- 使用yarn:
- 执行
yarn cache clean清理缓存 - 删除项目根目录下的
node_modules文件夹和yarn.lock文件 - 执行
yarn install重装依赖
- 执行
- 使用npm:
- 检查版本兼容性:查看当前Next.js版本对
caniuse-lite的版本要求,安装对应版本的包(可在项目package.json的peerDependencies或Next.js官方文档中确认)
内容的提问来源于stack exchange,提问作者user15194898
相关产品推荐
相关产品推荐

