【发布时间】:2022-01-21 07:11:14
【问题描述】:
请看Issue
我很确定包和我都没有使用require(),但仍然有一个错误告诉我不要使用require()
这太奇怪了!
有错误的代码:
import stripAnsi from 'strip-ansi';
错误:
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\13931\Desktop\ucon\node_modules\strip-ansi\index.js from C:\Users \13931\Desktop\ucon\src\utty.ts not supported.
Instead change the require of index.js in C:\Users\13931\Desktop \ucon\src\utty.ts to a dynamic import() which is available in all commonjs modules.
而最令人困惑的是:
import 语句在任何地方都有帮助,除了导入 strip-ansi!
【问题讨论】:
-
没有看到您的代码,我不确定我们应该如何帮助您。
-
@msanford 非常感谢,但这不是我的问题。
-
您是否可能使用 TypeScript 进行编码并为 ES5 设置编译目标或生成
require()而不是使用import?我建议你看看你生成的 JS 代码,看看它在做什么。 -
@jfriend00 你是对的!我的天啊!我从我忘记的地方复制了 tsconfig.json,它有 module:"commonjs" !!!!!!非常感谢!!!!!!
标签: node.js typescript import require es6-modules