-
Notifications
You must be signed in to change notification settings - Fork 136
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
Why are source maps not working right in dev mode? #426
Comments
This must have been fixed? I'm getting the correct filename (../Dashboard.tsx) and line (211) in my developer console. |
Hm, maybe it's platform dependent? I just tried it on a computer with:
and it still looks exactly like the screenshot. Are you on a different OS/browser, or different versions of those tools? |
I tried it on:
I initially tried the most obvious solution, which was to use a different browser. I went over to Firefox and saw the same, correct, error output. Then I upgraded yarn to 1.22.19 and saw the same. Next, I used NVM to switch my active version of Node to match 16.16.0, and still saw the same, correct, error output. At this point, it seems it could be an OS issue. Fortunately, I also have Ubuntu installed on my machine, so I will now switch over to that and see if it's an OS issue for whatever reason. Give me just a few minutes. |
You know what, disregard my last post. I misunderstood your initial post. Mine actually does incorrectly link to the DraftScouting.tsx file as well. What threw me off was it displaying the Dashboard.tsx, but I see that it does that in your initial screenshot as well. Now I understand the problem. I will continue to mess around with it as I do have a decent amount of experience working with esbuild, which is what drew me to this post. It's certainly puzzling. Hopefully I can stumble upon something for you. |
My error looks like:
When I focus on the What if we change the sourcemap type? -- https://esbuild.github.io/api/#sourcemap Just going to run some tests. tried the 3 other methods listed in the docs
Switching back to linked
Which files are listed as
Why are some files What do these
Which directories have more
|
Yeah I see the same error you do now. It is better to say it's in an unknown file rather than say it's in the wrong file, but it'd still be better if it said what the actual file was. Also I'm not sure if you meant to include more in your previous comment, or if you're going to write another comment? Seems to end abruptly :) |
Yes. Sorry I had to run out quickly, never got to finish my last thought. Do you know which of these files are not bundled? And why are they not bundled? I believe 6 of them are not bundled, but not 100 % on that
That makes a lot of sense. Looks like these 10 files get bundled as
|
The types*.ts contain only TypeScript types, not actual JS code. So they don't get bundled. bySport.ts is just a placeholder for TypeScript, when it's actually compiled it gets replaced by https://github.com/zengm-games/zengm/tree/master/tools/babel-plugin-sport-functions polyfills.ts are only included in the legacy build, it's not included in the modern build or in dev mode. The others should be included in the bundle, I think. |
I am thinking a lot about The ten files we have narrowed down to
Does this mean that If so, can the plugin step of compiling have an effect on the final source map?
|
I think you're right! Originally I wanted to run that Babel plugin to replace isSport/bySport only in prod, but I realized it's actually required in dev too because the bySport code blocks for different sports all being simultaneously executed can sometimes result in errors. It would be better if they were all wrapped in IIFEs, but that makes the syntax uglier, so I decided to rely on my Babel plugin in dev too. So anyway, it is possible to delete that plugin, it might break some stuff but most things still work. And deleting the plugin fixes the stack trace! https://esbuild.github.io/plugins/ has examples of plugins that maintain source maps. IIRC it may have even had a Babel plugin example in the past, similar to what I'm doing. So in theory what I'm doing should work - inline source maps emitted from the plugin. So I'm still not sure why my plugin doesn't work! Regarding the bounty, does this sound fair? $100 to @ldrobner know for identifying the source of the problem, and $100 in the future if you can figure out how to actually fix it? If so email me jeremy@zengm.com with how you want to be paid, Paypal is easiest but I can probably do others. |
Hello. I have been trying to read through some more of the esbuild documentation. Mostly reading about plugin callback functions -- https://esbuild.github.io/plugins
|
I don't think you can process file contents in onResolve.
It does, because there's no way to tell if it's needed without looking in the file. zengm/tools/lib/esbuildConfig.js Lines 51 to 54 in 5da268a
The former is the setting for babel, the latter is the setting for esbuild. So they are different settings with different allowed values. The way it should be working is that babel emits an inline sourcemap in each file it processes, and then esbuild notices those inline sourcemaps and uses that knowledge when creating its final sourcemaps. Something is probably going wrong in one of those processes - either babel is producing a somehow incorrect sourcemap, or esbuild is not correctly parsing/using the sourcemaps from babel. Or I am configuring it wrong, that's also possible, but I don't think I am. |
I logged each "exit"/setting of 'result' into a file to see if there was anything different between babel transformed files and the files you simply return the text of. Printed out a lot of information and I have yet to make sense of all of it, but I am unsure if the I have not confirmed this theory, but I have been thinking about this line: zengm/tools/lib/esbuildConfig.js Line 15 in 5da268a
Do you think that babel or esbuild is changing the Taking a step back and going back to my original comment
I am thinking a solution could be setting a strict order of bundling. My concern is that esbuild already takes care of this. I am unsure how files are read and added to the source map, but my best guess would be a type of post order traversal system. We are passing I am going to simplify my logging and try and check the order of which files are bundled. Also looking at the Wondering if we could using something like a source-base-path feature could help with this issue. -- evanw/esbuild#2554 Let me know if I made any sense here. |
mtime is modification time, so reading the file shouldn't change it. In theory there could be a bug, but it'd be a very weird one, because it'd have to be updating mtime without also triggering a rebuild from watching for changed files. The point of babelCache is for updates, not for the initial run.
In general, I think my code is pretty mundane, and I think I may have originally copied most of it from the esbuild docs or something similar. So idk, I feel like it should work as is, but clearly it doesn't. The solution probably isn't something super complicated though. |
Makes sense. I have been thinking more about on resolve callbacks. I believe we can use on resolve callbacks to help better set the file's path in the map file. I will try and test some theories and get a PR out. |
hello. Sorry for the delay. I tried out 2 more solutions:
Would love to commit this, but I get a 403 when trying to. Let me know if this make sense. Happy to commit, etc, just let me know. |
Wow, incredible! You are a true hero for figuring this out. If you want to commit, you have to fork the repo and then make a PR from one of your branches. If you'd like to do that, please go ahead! Otherwise I can make the change myself, but I understand if you want that commit as a trophy for figuring all this out :) |
Actually it's still not solved! Changing it to zengm/tools/lib/esbuildConfig.js Lines 31 to 41 in 5da268a
code property. So in this case, the source map is ignored. It's the same as setting sourcemaps to false .
So if the error happens inside or after a The "inline" setting would include the source map in the code. And to some extent that is working, otherwise it wouldn't get the correct line number. Just the file name is being lost somehow. |
Hmm. I think I understand what you are saying. Why does changing
As I messed around with the configuration more, I noticed something... This makes me want to circle back to onResolve. Seems like esbuild is unable to resolve the path of files that use I re-added the onResolve callback from before:
And I shortened the |
$200 prize if you can resolve this issue, see below for detail
I made a branch https://github.com/zengm-games/zengm/tree/esbuild-sourcemaps containing a commit f0d524f which throws an error when the main page is loaded. Try it out:
$ git checkout esbuild-sourcemaps
$ yarn install
$ yarn run start-watch
Go to http://localhost:3006 in your browser and observe an error in the console like this:
So it thinks the error is on line 211 of src/ui/views/DraftScouting/index.tsx, but actually it's on line 211 of src/ui/views/Dashboard.tsx. It got the line number right, but the file wrong. Seems this happens to any error I introduce anywhere in the codebase - the source maps get the line number right, but the file wrong. Very annoying.
This must have something to do with esbuild, since it happens only in dev where esbuild is used, rather than in prod where rollup is used.
I spent some time poking around to try to figure out what's going on, but I couldn't figure it out.
If someone can tell me how to fix this, I will give you $200. By "fix" I don't mean something crazy like "switch back to using rollup in dev mode, which is like 1000x slower than esbuild".
The text was updated successfully, but these errors were encountered: