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.

Debug w/ Create React App does not seem to work.

See original GitHub issue

Environment

  1. node -v: 8.9.4

  2. npm -v: 5.6.0

  3. npm ls react-scripts (if you haven’t ejected): react-scripts@1.0.17

  4. Operating system: OSX 10.13.2

Steps to Reproduce

  1. open vscode and ensure I have the latest vscode-jest installed
  2. npx create-react-app my-app
  3. cd my-app && yarn add @types/jest
  4. Create the .vscode/launch.json file and add the following configuration, from the create-react-app readme.
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug CRA Tests",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",      
      "args": [
        "test",
        "--runInBand",
        "--no-cache",
        "--env=jsdom"
      ],
      "cwd": "${workspaceRoot}",
      "protocol": "inspector",
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    }
  ]
}

source: https://github.com/facebook/create-react-app/blob/ed5c48c81b2139b4414810e1efe917e04c96ee8d/packages/react-scripts/template/README.md#debugging-tests-in-visual-studio-code

  1. Add the following test to src/App.test.js
it('SIMPLE TEST', () => {
  let x = 1;
  let y = 2;
  expect(1).toEqual(2);
});
  1. Add a breakpoint, and Click the Debug lens above the test.

Expected Behavior

The debug overlay to open and the debugger to break.

Actual Behavior

Error: Cannot find jest.js file


Note: Following some research elsewhere on this issue queue and elsewhere I’ve also tried setting my jest.pathToJest in my .vscode/settings.json to a number of different settings with no luck.

Reference:

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
beaksandclawscommented, Feb 1, 2018

Hey! So I was experiencing the exact same problem, and it turned out I needed to add a .babelrc to the root of my project with just the following:

{
  "presets": [
    "react-app"
  ]
}

You may need to restart vscode, but I’m not totally sure.

0reactions
fabienjuifcommented, Mar 28, 2020

In same way, and for those who don’t like having a lot of configuration file at root of their projects, you can add this to your package.json:

  "babel": {
    "presets": [
      "react-app"
    ]
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

React App Not Working? 4 Quick Debugging Tips - Dave Ceddia
If your app is broken, try these things first.
Read more >
Debugging create-react-app Build used for Unpacked Chrome ...
My current build process is to build the project with create-react app, then load the unpacked build as an extension.
Read more >
Debugging React Apps Created With Create React App in ...
Learn how to get started with debugging a React application that is running on the localhost.
Read more >
Strict Mode - React
Strict mode checks are run in development mode only; they do not impact the production build. You can enable strict mode for any...
Read more >
Creating a React App - Codecademy
We will use npx, a package runner tool that comes with npm 5.2+ and higher, to install and run create-react-app . This will...
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