Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack5 doesn't work due to 'debug' named export #452

Open
DanailPenev opened this issue Mar 27, 2022 · 2 comments · May be fixed by #462
Open

Webpack5 doesn't work due to 'debug' named export #452

DanailPenev opened this issue Mar 27, 2022 · 2 comments · May be fixed by #462

Comments

@DanailPenev
Copy link

Describe the bug
Using the openapi-to-graphql library in projects using webpack 5 throws a runtime error due to issues with CommonJS/ESM. This is similar to the issue observed in other libraries, e.g. graphql/graphql-js#2721 or https://stackoverflow.com/questions/70615613/apollo-client-named-export-remove-not-found

To Reproduce

  • Add openapi-to-graphql to a project using webpack 5
  • Call createGraphQLSchema
  • Try opening the page triggering this behaviour
  • You should see an error in the console

Expected behavior

  • createGraphQLSchema should work as expected

Error log

CommonJS modules can always be imported via the default export, for example using:
import pkg from 'debug';
const { debug: debug$1 } = pkg;
error - unhandledRejection: SyntaxError: Named export 'debug' not found. The requested module 'debug' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'debug';
const { debug: debug$1 } = pkg;

Additional context
This seems to have been introduced in openapi-to-graphql 2.5.0. More specifically I suspect that it was this commit 74d7163

Removing the exports object from the package.json has worked as a temporary solution for me.

@Alan-Cha
Copy link
Collaborator

@DanailPenev Thanks for reporting this issue. Unfortunately, I'm a bit at a loss for how to address this problem. I am reading into it but do you have any suggestions?

@Zn4rK
Copy link

Zn4rK commented May 23, 2022

The problem is with how the packages debug and pluralize are imported, since both of these are CommonJS. The CJS export (dist/index.js) works fine, since it uses good old require. But the esm module needs to be corrected. The only thing that would be needed is to be a bit more consistent in how the imports are handled.

import * as pluralize from 'pluralize'

Needs to be changed to:

 import pluralize from 'pluralize' 

And

Needs to changed into:

 import debug from 'debug' 

ESM should be fixed by this, and CommonJS should still be working.

Give me a few minutes and I'll create a PR.

Until that is merged and released, one can still use this package with Webpack (but not have as good tree shaking capabilities) by using cjs: const { createGraphQLSchema } = require('openapi-to-graphql');.

@Zn4rK Zn4rK linked a pull request May 23, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants