question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Breakpoints & sourcemaps do not work with a react native setup in Webstorm

See original GitHub issue
  • Issue

When running a react native configuration, it is impossible for me to get any breakpoints to register in Webstorm. Debugger statements work but do not break at the correct line.

I have a suspicion that the sourcemaps are to blame. This is an example of it breaking before the debugger statement: billede

However when I remove the typescript interface it breaks like this: billede

My thoughts are, that it is using an es6 sourcemap, and not the typescript sourcemaps. My tsconfig is set to enable inline sourcemaps, and looks like this:

{
    "compilerOptions": {
        "jsx": "react",
        "allowSyntheticDefaultImports": true,
        "target": "es2015",
        "moduleResolution": "node",
        "inlineSourceMap": true
    },
    "exclude": [
        "node_modules"
    ]
}

and jest config looks like this:

	"jest": {
		"preset": "react-native",
		"transform": {
			"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
			".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
		},
		"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
		"moduleFileExtensions": [
			"ts",
			"tsx",
			"js",
			"json"
		],
		"globals": {
			"__DEV__": true
		}
	}

I do not know if this is a webstorm or jest regression, or whether the react native build setup has anything to do with it.

  • Expected behavior

I expect to be able to set breakpoints, and that the debugger statements stop at the correct place.

  • Link to a minimal repo that reproduces this issue

This is a minimal repo that reproduces the issue. Simply go to the some-test.test.tsx, and in webstorm left click on the test and click debug. https://github.com/GeeWee/rn-typescript-example/tree/ts-loader-bug

I’m not sure how to set up any test cases for this particular bug.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
GeeWeecommented, May 11, 2017

Yes that makes perfect sense! Because babel-jest ( at least with the react native preset ) creates synthetic default exports that typescript can grab.

It seems like the problem here would be that if the ts files are passed to babel-jest, the sourcemaps are not included.

I have set sourceMaps: "inline" in my .babelrc and it seems to allow me to set breakpoints and not fail my tests. I’ve updated my repo - can you see if it works for you?

I would be willing to do a PR explaining a more detailed react-native setup guide. (e.g. someone should really mention it pipes it through babel-jest if you use allowSyntheticDefaultImports - I spent quite a bit of time on a preprocessor that would do essentially the same thing)

1reaction
GeeWeecommented, May 14, 2017

I have created #212 for the VSCode issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging React Apps Created With Create React App in ...
Set breakpoints in your code​​ WebStorm recognizes line breakpoints, exception breakpoints, and conditional breakpoints. To set a line breakpoint ...
Read more >
ReactNative + TypeScript + WebStorm - debugging not working
I have problem with debugging of my ReactNative app written in TypeScript when I use WebStorm IDE. Application works, but when I put ......
Read more >
Stop Painful JavaScript Debug and Embrace Intellij ... - Medium
Launch the configuration in debug mode and then set a breakpoint in your code (a check mark appears). Your app will be launched...
Read more >
Debugging - React Native
While sourcemaps may not be enabled by default, you can follow this guide or video to enable them and set break points at...
Read more >
How To Run TypeScript In WebStorm - Tabnine
To debug TypeScript in WebStorm, you can create breakpoints in your code by click on the line number. This will produce a red...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found