在 nextjs 中使用 ahooks 时,报错 SyntaxError: Cannot use import statement outside a module,如下图所示:
解决方案
- transpilePackages 官网介绍
Next.js can automatically transpile and bundle dependencies from local packages (like monorepos) or from external dependencies (
node_modules). This replaces thenext-transpile-modulespackage.
翻译:Next.js 可以自动从本地包(如 monorepos )或外部依赖项转译和捆绑依赖项 node_modules 。这将替换 next-transpile-modules 包。
- 配置
1 | |
参考文档:
- https://github.com/alibaba/hooks/issues/2254
- https://nextjs.org/docs/app/api-reference/next-config-js/transpilePackages
欢迎访问:天问博客
本文作者: Tiven
发布时间: 2024-01-06
最后更新: 2024-01-10
本文标题: nextjs + ahooks 报错 Cannot use import statement outside a module
本文链接: https://www.tiven.cn/p/e4d0c5d6/
版权声明: 本作品采用 CC BY-NC-SA 4.0 许可协议进行许可。转载请注明出处!
发布时间: 2024-01-06
最后更新: 2024-01-10
本文标题: nextjs + ahooks 报错 Cannot use import statement outside a module
本文链接: https://www.tiven.cn/p/e4d0c5d6/
版权声明: 本作品采用 CC BY-NC-SA 4.0 许可协议进行许可。转载请注明出处!


