这边引入了一个库,然后用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.
有这块懂的能帮忙解答下嘛?谢谢了
你在
ES Module
项目中引入了Commonjs
规范的库, 试试这样,没试过