graphql-editor / graphql-zeus

GraphQL client and GraphQL code generator with GraphQL autocomplete library generation ⚡⚡⚡ for browser,nodejs and react native ( apollo compatible )
https://graphqleditor.com/docs/zeus
MIT License
1.95k stars 106 forks source link

Getting ERR_UNSUPPORTED_DIR_IMPORT when generating #402

Open Rdeisenroth opened 4 months ago

Rdeisenroth commented 4 months ago

Hi, on all of my machines, when i run zeus src/backend/prisma/generated/schema.graphql src/backend/prisma/generated/zeus --typescript --apollo, i get the following error ( is a placeholder for the actual pwd):

node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '<repo_path>/node_modules/rxjs/operators' is not supported resolving ES modules imported from <repo_path>/node_modules/config-maker/lib/utils/AwfulAutoCompletePrompt.js
Did you mean to import rxjs/operators/index.js?
    at finalizeResolution (node:internal/modules/esm/resolve:249:11)
    at moduleResolve (node:internal/modules/esm/resolve:908:10)
    at defaultResolve (node:internal/modules/esm/resolve:1121:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file://<repo_path>/node_modules/rxjs/operators'
}

it can be fixed, if i manually edit AwfulAutoCompletePrompt.js, line 11:

-import { takeWhile } from 'rxjs/operators';
+import { takeWhile } from 'rxjs/operators/index.js';

However the error always reappears when i install another package with yarn add.

Rdeisenroth commented 4 months ago

As a temporary workaround, i added a file called postinstall.ts to src/scripts:

import * as fs from 'fs';
import * as path from 'path';

// See https://github.com/graphql-editor/graphql-zeus/issues/402
const filePath = path.resolve('node_modules/config-maker/lib/utils/AwfulAutoCompletePrompt.js');
const fileContent = fs.readFileSync(filePath, 'utf8');

const fixedContent = fileContent.replace(
    "import { takeWhile } from 'rxjs/operators';",
    "import { takeWhile } from 'rxjs/operators/index.js';"
);

fs.writeFileSync(filePath, fixedContent, 'utf8');
console.log('Fixed rxjs import in AwfulAutoCompletePrompt.js');

and edited my package.json like so:


{
  "scripts": {
    "postinstall": "ts-node --require tsconfig-paths/register --require reflect-metadata src/scripts/postinstall.ts",
  }
}