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

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  阅读(459)  评论(0)  编辑  收藏  举报
会员力量,点亮园子希望
刷新页面返回顶部
Copyright © 2024 unfetteredman
Powered by .NET 8.0 on Kubernetes