node.js - 如何处理第三方包中 CommonJS 和 ECMAScript 模块的混合
我正在为一个应用程序编写 NodeJS 后端。它使用 graphql 和 graphql-yoga。应用程序使用 tsx 运行正常,但当我尝试构建应用程序时,我在同一文件夹中的不同 .cts 文件中遇到了多个此类错误:
node_modules/@graphql-yoga/subscription/typings/operator/map.d.cts:1:26
- 错误 TS1479:当前文件是一个 CommonJS 模块,其导入将生成 'require' 调用;然而,被引用的文件是一个 ECMAScript 模块,不能使用 'require' 导入。考虑改为使用动态 'import("@repeaterjs/repeater")' 调用。
1 导入 { Repeater } 从 '@repeaterjs/repeater';
有没有办法调整我的编译器选项或其他什么来修复这个问题?
tsconfig.json:
{
"compilerOptions": {
"esModuleInterop": true,
"isolatedModules": true,
"module": "Node16",
"moduleResolution": "Node16",
"allowSyntheticDefaultImports" : true,
"useUnknownInCatchVariables": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2020",
},
"type": "module",
"compileOnSave": true,
"paths": {
},
"include": [
"./src/**/*.ts",
"./src/**/*.d.ts",
"./test/**/*.ts",
"./test/**/*.d.ts",
"index.ts",
"./.eslintrc.js",
"./jest.config.js",
]
}