octokit / graphql-schema

GitHub’s GraphQL Schema with validation. Automatically updated.
MIT License
176 stars 62 forks source link

[BUG]: `@octokit/graphql-schema v15` causes [ERR_PACKAGE_PATH_NOT_EXPORTED] due to missing "exports" main in package.json #941

Closed ProchaLu closed 5 months ago

ProchaLu commented 5 months ago

What happened?

When running graphql-codegen --config codegen.yml in this project after updating the @octokit/graphql-schema from v14.46.1 to v15.15.0. The error message shows that the schema cannot be loaded due to the absence of the "exports" main in the package.json of "@octokit/graphql-schema".

> portfolio-next@0.1.0 gen /home/runner/work/next-portfolio-dev/next-portfolio-dev
> graphql-codegen --config codegen.yml

[STARTED] Parse Configuration
[SUCCESS] Parse Configuration
[STARTED] Generate outputs
[STARTED] Generate to src/generated/graphql.ts
[STARTED] Load GraphQL schemas
[FAILED] 
[FAILED]         Failed to load schema from src/generated/github-schema-loader.cjs:
[FAILED] 
[FAILED]         Unable to load from file "/home/runner/work/next-portfolio-dev/next-portfolio-dev/src/generated/github-schema-loader.cjs": Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/runner/work/next-portfolio-dev/next-portfolio-dev/node_modules/@octokit/graphql-schema/package.json
[FAILED]     at exportsNotFound (node:internal/modules/esm/resolve:304:10)
[FAILED]     at packageExportsResolve (node:internal/modules/esm/resolve:594:13)
[FAILED]     at resolveExports (node:internal/modules/cjs/loader:590:36)
[FAILED]     at Module._findPath (node:internal/modules/cjs/loader:667:31)
[FAILED]     at Module._resolveFilename (node:internal/modules/cjs/loader:1129:27)
[FAILED]     at Module._load (node:internal/modules/cjs/loader:984:27)
[FAILED]     at Module.require (node:internal/modules/cjs/loader:1231:19)
[FAILED]     at require (node:internal/modules/helpers:179:18)
[FAILED]     at Object.<anonymous> (/home/runner/work/next-portfolio-dev/next-portfolio-dev/src/generated/github-schema-loader.cjs:3:20)
[FAILED]     at Module._compile (node:internal/modules/cjs/loader:1369:14)
[FAILED]         Error: Unable to load from file "/home/runner/work/next-portfolio-dev/next-portfolio-dev/src/generated/github-schema-loader.cjs": Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/runner/work/next-portfolio-dev/next-portfolio-dev/node_modules/@octokit/graphql-schema/package.json
[FAILED]     at exportsNotFound (node:internal/modules/esm/resolve:304:10)
[FAILED]     at packageExportsResolve (node:internal/modules/esm/resolve:594:13)
[FAILED]     at resolveExports (node:internal/modules/cjs/loader:590:36)
[FAILED]     at Module._findPath (node:internal/modules/cjs/loader:667:31)
[FAILED]     at Module._resolveFilename (node:internal/modules/cjs/loader:1129:27)
[FAILED]     at Module._load (node:internal/modules/cjs/loader:984:27)
[FAILED]     at Module.require (node:internal/modules/cjs/loader:1231:19)
[FAILED]     at require (node:internal/modules/helpers:179:18)
[FAILED]     at Object.<anonymous> (/home/runner/work/next-portfolio-dev/next-portfolio-dev/src/generated/github-schema-loader.cjs:3:20)
[FAILED]     at Module._compile (node:internal/modules/cjs/loader:1369:14)
[FAILED]     at tryToLoadFromExport (/home/runner/work/next-portfolio-dev/next-portfolio-dev/node_modules/.pnpm/@graphql-tools+code-file-loader@8.0.2_graphql@16.7.1/node_modules/@graphql-tools/code-file-loader/cjs/load-from-module.js:38:15)
[FAILED]     at async CodeFileLoader.handleSinglePath (/home/runner/work/next-portfolio-dev/next-portfolio-dev/node_modules/.pnpm/@graphql-tools+code-file-loader@8.0.2_graphql@16.7.1/node_modules/@graphql-tools/code-file-loader/cjs/index.js:186:32)
[FAILED]     at async /home/runner/work/next-portfolio-dev/next-portfolio-dev/node_modules/.pnpm/@graphql-tools+code-file-loader@8.0.2_graphql@16.7.1/node_modules/@graphql-tools/code-file-loader/cjs/index.js:110:32
[FAILED]     at async Promise.all (index 0)
[FAILED]     at async CodeFileLoader.load (/home/runner/work/next-portfolio-dev/next-portfolio-dev/node_modules/.pnpm/@graphql-tools+code-file-loader@8.0.2_graphql@16.7.1/node_modules/@graphql-tools/code-file-loader/cjs/index.js:108:9)
[FAILED]     at async /home/runner/work/next-portfolio-dev/next-portfolio-dev/node_modules/.pnpm/@graphql-tools+load@8.0.0_graphql@16.7.1/node_modules/@graphql-tools/load/cjs/load-typedefs/load-file.js:15:39
[FAILED]     at async Promise.all (index 0)
[FAILED]     at async loadFile (/home/runner/work/next-portfolio-dev/next-portfolio-dev/node_modules/.pnpm/@graphql-tools+load@8.0.0_graphql@16.7.1/node_modules/@graphql-tools/load/cjs/load-typedefs/load-file.js:13:9)
[FAILED]     at async /home/runner/work/next-portfolio-dev/next-portfolio-dev/node_modules/.pnpm/@graphql-tools+load@8.0.0_graphql@16.7.1/node_modules/@graphql-tools/load/cjs/load-typedefs/collect-sources.js:229:25
[FAILED] 
[FAILED]         GraphQL Code Generator supports:
[FAILED]           - ES Modules and CommonJS exports (export as default or named export "schema")
[FAILED]           - Introspection JSON File
[FAILED]           - URL of GraphQL endpoint
[FAILED]           - Multiple files with type definitions (glob expression)
[FAILED]           - String in config file
[FAILED] 
[FAILED]         Try to use one of above options and run codegen again.
[FAILED] 
[FAILED]       
[SUCCESS] Generate outputs

Also there the failing test

I am loading the current schema directly as JSON in this github-schema-loader.cjs file

require('@graphql-codegen/typescript');
require('@graphql-codegen/typescript-operations');
const { schema } = require('@octokit/graphql-schema');

module.exports = schema.json;

and using this github-schema-loader.cjs in the schema for the GraphQL codegen in this yml file

overwrite: true
schema: 'src/generated/github-schema-loader.cjs'
generates:
  src/generated/graphql.ts:
    plugins:
      - 'typescript'
      - 'typescript-operations'

Versions

Node.js v20.12.1 pnpm 9.0.6

    "@graphql-codegen/cli": "5.0.2",
    "@graphql-codegen/typescript": "^4.0.1",
    "@graphql-codegen/typescript-operations": "^4.0.1",
    "@octokit/graphql-schema": "15.15.0",

Relevant log output

No response

Code of Conduct

github-actions[bot] commented 5 months ago

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

wolfy1339 commented 5 months ago

This package is ESM. You will need to change your code.

The error given is misleading