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

Sources imported via text loader doesn't appears in source maps #2041

Closed
tinovyatkin opened this issue Feb 22, 2022 · 1 comment
Closed

Sources imported via text loader doesn't appears in source maps #2041

tinovyatkin opened this issue Feb 22, 2022 · 1 comment

Comments

@tinovyatkin
Copy link

I need to get source reference for original file imported via text loader (in may case it's *.graphql file), but unfortunately I don't see original source entry in the sources array of generated source map. Do I missing something or it's a bug?

Example of source:

import SiteQuery from '@common/graphql/queries/site/site.graphql';
console.log(SiteQuery);

Bundles as expected (with loader: { '.graphql': 'text' } option) into (including comment that points to the file properly):

// ../common/graphql/queries/site/site.graphql
var site_default = '#import "../../fragments/site.graphql"\n\nquery Site($input: SiteInput!) {\n  site(input: $input) {\n    ...SiteFragment\n  }\n}\n';
console.log(site_default)

but there is no site.graphql entries in souce map sources array.

@hyrious
Copy link

hyrious commented Feb 23, 2022

This is intentional behavior in esbuild because it only outputs sourcemaps which are helpful in showing logs (errors, warnings). Basically they (helpful debug points) are the places that could throw errors, like accessing a variable name, accessing a getter, calling a function, etc. That's why it will choose these | places shown below.

|console.|log(|42)

A string from text loader doesn't trigger any errors or warnings, so esbuild won't preserve it in the output.

var a = |"text" // useless

However, you're free to write a plugin that makes use of on-end callback to append the missing sourcemap.

@evanw evanw closed this as completed in 7e10dd6 Jun 26, 2023
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

No branches or pull requests

2 participants