小编Mic*_*ich的帖子

错误:将 recharts 与 next.js (和 typescript)一起使用时,不支持 ES 模块的 require()

我看到了一些此类问题,但没有一个真正解决我的问题。我正在使用next.js(使用打字稿)开发一个网络应用程序。在我的应用程序中使用recharts,但编译失败并出现以下错误:

Error: Must use import to load ES Module: project_path\node_modules\d3-shape\src\index.js
require() of ES modules is not supported.
require() of project_path\node_modules\d3-shape\src\index.js from project_path\node_modules\recharts\lib\shape\Symbols.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from project_path\node_modules\d3-shape\package.json.
Run Code Online (Sandbox Code Playgroud)

现在,我使用 next.js 12,它支持开箱即用的 ES …

typescript es6-modules next.js recharts

13
推荐指数
1
解决办法
9065
查看次数

标签 统计

es6-modules ×1

next.js ×1

recharts ×1

typescript ×1