How to deal with mix of CommonJS and ECMAScript modules in 3rd party packages

I'm writing a NodeJS backend for an application. It uses graphql and graphql-yoga. The application runs fine using tsx, but when I attempt to build the application I get several instances of this error (from different .cts files in that same folder):

node_modules/@graphql-yoga/subscription/typings/operator/map.d.cts:1:26

  • error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@repeaterjs/repeater")' call instead.

1 import { Repeater } from '@repeaterjs/repeater';

Is there a way to adjust my compiler options or something to fix this?

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", ] } 
3

Related questions 2 Angular 11 problem with native web worker - Element 1 TypeScript definition for StoreEnhancer prevents rest parameters 0 Typescript ambient modules are not resolved when i build project with webpack and ts-loader Related questions 2 Angular 11 problem with native web worker - Element 1 TypeScript definition for StoreEnhancer prevents rest parameters 0 Typescript ambient modules are not resolved when i build project with webpack and ts-loader 659 How to download a file with Node.js (without using third-party libraries)? 7 node_modules/mongoose/node_modules/mongodb/mongodb.ts34.d.ts:3288:5 - error TS1005: '?' expected 0 Import statement was not compiled if it was not used later 292 How do I use namespaces with TypeScript external modules? 3 Typescript not finding 3rd party modules from 'node_modules' folder 2 Mix Node's CommonJS and Typescript's ES modules Load 6 more related questions Show fewer related questions

Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like