当前位置: 首页 > 知识库问答 >
问题:

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

秦信瑞
2023-11-18

这边引入了一个库,然后用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个答案

詹钊
2023-11-18

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

const ID3Writer = require('browser-id3-writer');
 类似资料: