-
Notifications
You must be signed in to change notification settings - Fork 451
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
Line numbers aren't mapped correctly in TSX files when using Node 8 AND React 16 #334
Comments
Thanks for reporting this. I was able to reproduce this issue. It looks related to react 16 in some way. |
Yes I think you're correct. I would be happy to help on this if you point me in the right direction of what in React 16 might have changed the error line mappings? |
I've pushed an additional change to your PR which should, hopefully, result in a failed build. It'll be good to have a common point of reference when debugging this issue.
The issue appears to arise due to some changes in react-test-renderer |
Sounds good! |
Yeah react-test-renderer is where I got to and then figured I was out of my element since I wasn't sure what it did. |
This is probably being caused due to the new error handling mechanism that React has. I'm not sure how this can be fixed in ts-jest. |
I wonder if we can add in a custom log output in componentDidCatch that captures the right line. |
componentDidCatch doesn't contain any line numbers |
:( Dang. |
they have some sort of a plugin for those using Babel but it won't help here |
If this is due to the react code - can we just throw our errors in non-react code? |
We just read So to fix it, you would need to either remove |
I'm not sure I understand. Could you please elaborate?
that's set by the
It isn't available at the moment the TypeScript file is processed. It wasn't required prior to v16 as all errors in
We don't currently use it but I actually think otherwise. We might need to use it if we can't find any solution. In that case as well, the plugin should be capable of using sourcemaps (that are emitted after we process
In the worst case, this might be the way to go. |
Curiously, it only fails in node version 8. I was able to reproduce this as part of #333 |
I'm not sure I understood it right the first time around. Do we still think this is due to react error boundaries? It only failing in node 8 says no to me, but it's very curious. |
React 16 didn't change anything in how line numbers are associated with JSX. There are only two things that changed:
React can't possibly affect the line numbers from JavaScript stack. Those are reported by the JavaScript engine. I now see that your report was about JS line numbers so my previous comments about JSX transform were not relevant. |
I'm going to try and find some time to dive deeper into this but in case someone else is looking at it, here's what the situation looks like:
|
Some debugging threw up this error message:
I have a suspicion that some code in react is throwing the built-up error and in the process (directly or indirectly) suppressing the stack trace |
Thanks for the insights.
|
Where do you see the stack trace being suppressed? |
Sorry about that! That was the result of some changes that I had made while debugging. Please disregard my previous comment (updated) |
I've spent some time on this and don't think this is an issue with ts-jest. ts-jest is processing the tsx files correctly and is adding the sourcemap as well as the code to use There's not much we can do about this here, I'm afraid. The readme needs to be updated with a note about react 16 + node 8. |
There's an issue when using React 16 with Node 8 (kulshekhar#334). Disabling this test temporarily so that we can continue with the updates
I noticed that I get correct source-mapping in thrown Errors when I set (To be clear, this doesn't mean I got correct code-coverage, just that errors thrown in TS files needed ts-jst to avoid babel). Maybe this helps? |
I was wondering if there is any more information or progress on this? I'm trying to set up Jest for the first time and stack trace line numbers are incorrect as per this issue. It's a little different for me:
I've sought support via Discord and there are unanswered Stack Overflow questions with the same issue, there doesn't seems to be any resolution or workaround. This seems like a pretty big problem. Does anyone more familiar with Jest & this issue know if this is affecting everyone using Jest + TypeScript or just isolated cases? It seems odd that it's been going on so long unresolved if it's affecting a large number of people. I'm not sure how I can make a case that we should be adopting Jest if I can't get source maps working correctly, but i've been working on this for several days and nothing seems to work so I'm pretty baffled. I've tried various workarounds from older issues, e.g. turn on |
I fixed it by adding the
|
Tried adding |
Not sure what magic it is. |
@jamietre Did you try the CLI flag That's really strange :( |
@maoueh ! -- that's a big catch. I was only using the config option. I haven't tested the CLI flag. I don't know when I'll get to experiment with implementing that in our repo, but that's really key. |
For people coming to this issue from the FAQ, (that won't help create-react-app I suppose, as that's on an older version of jest) |
@huafu sorry, missed your message. I'm already a member of way too many Slacks, but you can join us over on Reactiflux? https://discord.gg/MWRhKCj |
Same problem for non-react projects - invalid stack trace line number. Node v12.16.1 (it is showing |
@fider-apptimia I had the same problem in non-react project when I was using This is how my
|
@adambbn here is my full tsconfig: {
"compilerOptions": {
"esModuleInterop": true,
"noImplicitAny": true,
"module": "CommonJS",
"moduleResolution": "node",
"allowJs": true,
"strict": true,
"isolatedModules": true,
"pretty": true,
"sourceMap": true,
"target": "ES2019",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"rootDir": "./",
"outDir": "./dist"
},
"exclude": ["dist", "node_modules"]
} Still invalid stack trace with |
Just in case someone stumbles on this issue in the future. I managed to make a minimal repro here I doubt this is something that ts-jest should handle/fix ? But if that can help another than I'm glad |
When using Node version 8 tsx-errors.spec.ts fails with:
I expect the test to pass.
This test is in the ts-jest repo so reproducing just involves upgrading to node 8 via nvm, n or some other method.
The text was updated successfully, but these errors were encountered: