請看問題
我很確定包和我都沒有使用 no 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 陳述句在任何地方都有幫助,除了 importing strip-ansi!
uj5u.com熱心網友回復:
確保您的 TypeScript 配置設定為適當的 Javascript 目標版本和適當的目標模塊型別,該型別支持并將使用,import以便 TypeScript 編譯器生成使用import. 如果沒有,那么它將生成使用require().
您可以隨時查看已編譯的(純 Javascript)代碼并查看它生成的內容。
uj5u.com熱心網友回復:
是的,我沒有使用任何require(). 但我錯誤地得到了
module:"commonjs"
在 tsconfig.json 中!
所以ts變成import了require...
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/387152.html
標籤:节点.js 打字稿 进口 要求 es6-modules
