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

Fix dependency issue when using @rollup/plugin-commonjs #5797

Merged
merged 3 commits into from
Oct 19, 2021

Conversation

DSergiu
Copy link
Contributor

@DSergiu DSergiu commented Oct 8, 2021

@rollup/plugin-commonjs has a hard time with this dependency and results in "undefined error" since gql is used before it is defined in the bundled code.

One can argue that the fix should be in the rollup plugin, but it is a tricky fix, and historically there were many attempts to solve it with no complete success.

@apollo-cla
Copy link

@DSergiu: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@glasser
Copy link
Member

glasser commented Oct 8, 2021

Is there an easy way to add "build with rollup" to our CI so that we don't reintroduce issues like this?

It would be nice to only have one import of the symbol in our code base. How about moving the import to packages/apollo-server-core/src/gql.ts, re-exporting from that file from index.ts, and importing from that file in the schema reporter file?

@DSergiu
Copy link
Contributor Author

DSergiu commented Oct 9, 2021

Is there an easy way to add "build with rollup" to our CI so that we don't reintroduce issues like this?

It would be nice to only have one import of the symbol in our code base. How about moving the import to packages/apollo-server-core/src/gql.ts, re-exporting from that file from index.ts, and importing from that file in the schema reporter file?

👍 Sure thing. I did extract gql into gql.ts and added a unit test which executes the es6 bundle with rolllup + commonjs.

To replicate the issue, import gql from index.ts import { gql } from '../..'; inside schemaReporter.js and run the test and you should get:

TypeError: (0 , __1.gql) is not a function

sourcemapExcludeSources: false,
};
const bundle = await rollup.rollup({
input: path.resolve(__dirname, '..', '..', 'dist', 'index.js'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth noting that I believe this works because our npm pretest script builds the package ahead of time.

@glasser
Copy link
Member

glasser commented Oct 19, 2021

Thanks, this looks good! We'll do our best to keep rollup working.

@glasser glasser merged commit c35086a into apollographql:main Oct 19, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants