Please see Issue
I'm very sure that neither the package and I used no require()
, but still got an error that tells me don't use require()
How weird it is!
code with error:
import stripAnsi from 'strip-ansi';
error:
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.
And the most confused thing is that: import statement is helpful everywhere except importing strip-ansi
!
Make sure that your TypeScript config is set for an appropriate target version of Javascript that supports import
so that the TypeScript compiler will generate code that uses import
. If not, then it will generate code that uses require()
.
You can always look at your compiled (plain Javascript) code and see what it is generating.
Yes, I didn't use any require()
. But I wrongly got
module:"commonjs"
in tsconfig.json!
so ts changed import
into require
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.