nextjs + ahooks 报错 Cannot use import statement outside a module

nextjs 中使用 ahooks 时,报错 SyntaxError: Cannot use import statement outside a module,如下图所示:

nextjs + ahooks

解决方案

  • transpilePackages 官网介绍

Next.js can automatically transpile and bundle dependencies from local packages (like monorepos) or from external dependencies (node_modules). This replaces the next-transpile-modules package.

翻译:Next.js 可以自动从本地包(如 monorepos )或外部依赖项转译和捆绑依赖项 node_modules 。这将替换 next-transpile-modules 包。

  • 配置
/** @type {import('next').NextConfig} */

const nextConfig = {
   
  transpilePackages: ['ahooks'],
}
 
module.exports = nextConfig

参考文档:


欢迎访问:天问博客

相关推荐

  1. IDEA

    2024-01-11 06:34:03       38 阅读
  2. sqoop运行

    2024-01-11 06:34:03       40 阅读
  3. yarn install

    2024-01-11 06:34:03       38 阅读
  4. 安装Paddlehub

    2024-01-11 06:34:03       35 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-11 06:34:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-11 06:34:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-11 06:34:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-11 06:34:03       18 阅读

热门阅读

  1. HJ12 字符串反转

    2024-01-11 06:34:03       37 阅读
  2. Linux中用于自动化交互式程序的工具!expect

    2024-01-11 06:34:03       37 阅读
  3. Spring面试整理-Spring注解

    2024-01-11 06:34:03       32 阅读
  4. webpack vite下px转vw方案postcss-px-to-viewport,兼容vant

    2024-01-11 06:34:03       34 阅读
  5. LeetCode 33. 搜索旋转排序数组

    2024-01-11 06:34:03       35 阅读
  6. opencv仿射变换

    2024-01-11 06:34:03       29 阅读
  7. selenium自动发数据到console并获取返回数据

    2024-01-11 06:34:03       40 阅读
  8. Windows+Qt5.14.2+android x86配置(待完善)

    2024-01-11 06:34:03       42 阅读