繁体   English   中英

我收到此错误,不知道如何解决

[英]I am getting this error and don't know how to resolve it

index.ts:5:8 - error TS1192: Module '"D:/Calculator/node_modules/@types/chalk-animation/index"' has no default export.

5 import chalkAnimation from "chalk-animation";
         ~~~~~~

index.ts:22:1 - error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher.

22 await welcome()

我正在尝试在 node.js 中使用 inquirer、chalk 和 chalk animation。虽然我的计算器在其他计算机上运行,但我不明白为什么它在我的计算机中显示此错误

在您的 tsconfig.json 文件中,在"compilerOptions"下,添加"esModuleInterop": true

{
    ...
    "compilerOptions": {
        ...
        "esModuleInterop": true,
        ...
    },
    ...
}

如果没有esModuleInterop , TypeScript 默认使用遗留机制解析导入名称,这不符合 ESM 规范,并且与 Node.js 在新代码中处理 CJS 模块导入的方式不兼容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM