0

I am debugging in VS code 1.42.1 with a React Native 0.61.5 app. Here is the launch.json:

    "version": "0.2.0",
    "configurations": [


        {
            "name": "Debug Android",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "android",
            "sourceMaps": true,
            "outDir": "${workspaceRoot}/.vscode/.react"
        },
        {
            "name": "Debug Android",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "android",
            "sourceMaps": true,
            "outDir": "${workspaceRoot}/.vscode/.react"
        },
        {
            "name": "Debug Android",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "android",
            "sourceMaps": true,
            "outDir": "${workspaceRoot}/.vscode/.react"
        },
        {
            "name": "Debug Android",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "android",
            "sourceMaps": true,
            "outDir": "${workspaceRoot}/.vscode/.react"
        },
    {
        "type": "node",
        "request": "attach",
        "name": "Attach by Process ID",
        "processId": "${command:PickProcess}"
    },
        {
            "type": "node",
            "request": "launch",
            "name": "Launch via NPM",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "run-script",
                "debug"
            ],
            "port": 9229
        },

        {
            "type": "node",
            "request": "launch",
            "name": "Launch index.js",
            "program": "${workspaceFolder}/emps_fe615\\index.js"  //<<== here is the entry point
        }
    ]
}

However there is error on debug console:

C:\Program Files\nodejs\node.exe --inspect-brk=24899 emps_fe615\index.js 
Debugger listening on ws://127.0.0.1:24899/1375f61a-e4a6-4f0f-b5fd-90b3b9d45d2a
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Wc:\D\code\js\emps_fe615\index.js:5
import {AppRegistry} from 'react-native';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1072:16)
    at Module._compile (internal/modules/cjs/loader.js:1122:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47
aiting for the debugger to disconnect...

Here is the index.js:

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);

Here is the portion of package.json:

  "dependencies": {
    "@react-native-community/async-storage": "^1.8.0",
    "@react-native-community/cli-platform-android": "^4.1.1",
    "@react-native-community/datetimepicker": "^2.2.2",
    "@react-native-community/masked-view": "^0.1.6",
    "moment": "^2.24.0",
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-audio": "^4.3.0",
    "react-native-confirmation-code-field": "^5.1.0",
    "react-native-confirmation-code-input": "^1.0.4",
    "react-native-device-info": "^5.5.3",
    "react-native-elements": "^1.2.7",
    "react-native-gesture-handler": "^1.6.0",
    "react-native-gifted-chat": "^0.13.0",
    "react-native-image-picker": "^2.3.0",
    "react-native-image-resizer": "^1.2.0",
    "react-native-keychain": "^4.0.5",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-modal": "^11.5.4",
    "react-native-modal-datetime-picker": "^8.3.0",
    "react-native-navbar": "^2.1.0",
    "react-native-reanimated": "^1.7.0",
    "react-native-safe-area-context": "^0.7.3",
    "react-native-screens": "^2.0.0-beta.10",
    "react-native-segmented-control-tab": "^3.4.1",
    "react-native-sound": "^0.11.0",
    "react-native-vector-icons": "^6.6.0",
    "react-navigation": "^4.1.1",
    "react-navigation-stack": "^2.1.1",
    "react-navigation-tabs": "^2.7.0",
    "socket.io-client": "2.1.1"
  },
  "devDependencies": {
    "@babel/core": "^7.8.4",
    "@babel/runtime": "^7.8.4",
    "@react-native-community/eslint-config": "^0.0.7",
    "babel-jest": "^25.1.0",
    "eslint": "^6.8.0",
    "jest": "^25.1.0",
    "metro-react-native-babel-preset": "^0.58.0",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }

Since the index.js is generated by react-native itself and was never changed. I have no clue about this error.

2
  • this is some sort of ts error, any plugin for ts you are using?
    – Gaurav Roy
    Commented Mar 6, 2020 at 5:37
  • Just posted package.json. Not as I am aware of.
    – user938363
    Commented Mar 6, 2020 at 6:35

1 Answer 1

1

Please try to add

transformIgnorePatterns: ['node_modules/(?!(react-native|react-native-button|native-base-.*|react-native-.*)/)'], to jest config

1
  • The error is the same with addition to jest. Here is the jest after adding the above line (added quotation mark): "jest": { "preset": "react-native", "transformIgnorePatterns": "['node_modules/(?!(react-native|react-native-button|native-base-.*|react-native-.*)/)']" }
    – user938363
    Commented Mar 13, 2020 at 17:49

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.