2

I'm trying to debug my tests for my React Redux app in VS Code.

Running my tests in Jest works great, but the when I run the debugger I get this error:

(function (exports, require, module, __filename, __dirname) { import * as actions from "../src/redux/actions/tasksActions";
                                                              ^^^^^^

SyntaxError: Unexpected token import

I'm using the following configuration in my launch.json:

{
      "type": "node",
      "request": "launch",
      "name": "Mocha Tests",
      "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
      "args": [
        "--require @babel/register",
        "--inspect-brk",
        "-u",
        "tdd",
        "--timeout",
        "999999",
        "--colors",
        "${workspaceFolder}/tests"
      ],
      "internalConsoleOptions": "openOnSessionStart"
    }

The first args in the config, "--require @babel/register", "--inspect-brk", came from suggestions on blogs I found while googling my error (the first arg was said to fix this exact error). Same error happens, though, with or without either of those args.

Here's my package.json if it helps.

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "@babel/cli": "^7.4.4",
    "@babel/core": "^7.4.4",
    "@babel/node": "^7.2.2",
    "@babel/preset-env": "^7.4.4",
    "@babel/register": "^7.4.4",
    "babel-jest": "^24.7.1",
    "chai": "^4.2.0",
    "enzyme": "^3.9.0",
    "expect": "^24.7.1",
    "jest": "^24.7.1",
    "jsdom": "^15.0.0",
    "mocha": "^6.1.4",
    "react-addons-test-utils": "^15.6.2",
    "react-scripts": "0.7.0"
  },
  "dependencies": {
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-redux": "^7.0.2",
    "redux": "^4.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "jest",
    "test:watch": "npm test -- --watch",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Any ideas? Thanks!

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Jonathan Tuzman
  • 11,568
  • 18
  • 69
  • 129

0 Answers0