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

Unable to bundle graphql #14

Closed
FallingSnow opened this issue Jan 11, 2021 · 8 comments
Closed

Unable to bundle graphql #14

FallingSnow opened this issue Jan 11, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@FallingSnow
Copy link

INFO Download https://esm.sh/graphql • https://esm.sh/graphql?target=es2018&dev
error: Uncaught (in promise) Error: Download https://esm.sh/graphql: Download https://esm.sh/graphql: 500 - Internal Server Error

When traversing to https://esm.sh/graphql?target=es2018&dev you get

/* esm.sh - error */
throw new Error("[esm.sh] " + "esbuild: \"graphql\" has already been declared");
export default null;
@shadowtime2000
Copy link

Looks like it is partially a problem with the graphql package and how they wrote it

@FallingSnow
Copy link
Author

Esbuild seems to have no problem bundling it locally.

app.tsx:

import * as Graphql from "graphql";
console.log(Graphql)
$ yarn add esbuild graphql
$ node_modules/.bin/esbuild app.tsx --bundle --outfile=out.js

@shadowtime2000
Copy link

Strange...

@shadowtime2000
Copy link

Maybe ESM is using an older version of esbuild?

@ije
Copy link
Member

ije commented Jan 11, 2021

@FallingSnow thanks, i will figure it out what happened.

@FallingSnow
Copy link
Author

I've worked out that the input going into esbuild is incorrect. Here is effectively the cause of the compiler fail:

export const { version,versionInfo,graphql, ....... } = graphql;

Note this is passed in at https://github.com/postui/esm.sh/blob/c61d1a05462a1d413f2b69797093e3ae54de7912/server/build.go#L465

An example of what the compiler is trying to compile:

const graphql = {
	graphql: "test"
};
export const { graphql } = graphql;
export default graphql;

Which results in

$ node script.js
file:///tmp/script.js:4
export const { graphql } = graphql;
               ^

SyntaxError: Identifier 'graphql' has already been declared
    at Loader.moduleStrategy (node:internal/modules/esm/translators:145:18)
    at async link (node:internal/modules/esm/module_job:47:21)

Now to find out why esbuild is being passed this.

@ije
Copy link
Member

ije commented Jan 16, 2021

@FallingSnow thanks for the details, it is vary useful for me, and i just fixed it! please try it agian: https://esm.sh/graphql.

ije pushed a commit that referenced this issue Jan 16, 2021
@ije ije added the bug Something isn't working label Jan 16, 2021
@FallingSnow
Copy link
Author

Great, it's working great! I'm finally only using esm.sh and denoland.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants