1

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",
  ]
}
Michel Floyd
  • 18,793
  • 4
  • 24
  • 39
Dov Rosenberg
  • 673
  • 6
  • 20
  • Seems like an issue with how your dependency was published. – morganney Jul 04 '23 at 14:27
  • What is odd is that your transitive dependency `@repeaterjs/repeater` has published a CJS build but uses `"private": true`: https://github.com/repeaterjs/repeater/blob/master/packages/repeater/rollup.config.js#L22. Seems both `graphql-yoga/subscription` and `@repeaterjs/repeater` support an ES build correctly, you might want to consider transitioning your project to ES modules. – morganney Jul 04 '23 at 14:53
  • Thanks @morganney – Dov Rosenberg Jul 04 '23 at 19:55

0 Answers0