Reputation: 63
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
!
Upvotes: 3
Views: 5411
Reputation: 707996
Make sure that your TypeScript config is set for an appropriate target version of Javascript and appropriate target module type that supports and will use 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.
Upvotes: 4