• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
逍遥汉
博客园    首页    新随笔    联系   管理    订阅  订阅

Nextjs SyntaxError: Cannot use import statement outside a module错误

NextJs 报 SyntaxError: Cannot use import statement outside a module 第三方依赖不能导入问题

 

解决方案:

1,Next.JS13.1+,可以使用next.config.js中的属性transpilePackages

const nextConfig = {
  transpilePackages: ['the-npm-package'], // 第三方的依赖
};
module.exports = nextConfig;

2,next-transpile-modules 一个NPM模块,它允许您指定要传输的模块。

// next.config.js
const withTM = require('next-transpile-modules')(['somemodule', 'and-another']); // pass the modules you would like to see transpiled

module.exports = withTM(withLess({
  ... // your custom next config
}));

 

时间如白驹过隙,忽然而已,且行且珍惜......
posted @ 2023-12-27 16:56  unfetteredman  阅读(1099)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3