tsc编译后运行报错Error [ERR_REQUIRE_ESM]: require() of ES Module,要怎么处理呢?

这边引入了一个库,然后用tsc编译index.ts后,报错 Error [ERR_REQUIRE_ESM]: require() of ES Module 了。需要怎么处理呢?

代码:
引入了这个库

然后创建了一个index.ts代码运行

import { ID3Writer } from 'browser-id3-writer';
console.log(ID3Writer)

然后就报错了:

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/yyy/Documents/node-music/node_modules/.pnpm/registry.npmmirror.com+browser-id3-writer@6.0.0/node_modules/browser-id3-writer/dist/browser-id3-writer.mjs not supported.
Instead change the require of /Users/yyy/Documents/node-music/node_modules/.pnpm/registry.npmmirror.com+browser-id3-writer@6.0.0/node_modules/browser-id3-writer/dist/browser-id3-writer.mjs to a dynamic import() which is available in all CommonJS modules.

有这块懂的能帮忙解答下嘛?谢谢了

阅读 1.5k
1 个回答

你在 ES Module 项目中引入了 Commonjs规范的库, 试试这样,没试过

const ID3Writer = require('browser-id3-writer');
推荐问题
logo
Microsoft
子站问答
访问
宣传栏