Chris-90
Chris-90

Reputation: 53

Unhandled error in debug adapter: SyntaxError: Unexpected token L in JSON at position 0

Error:

******** Unhandled error in debug adapter: SyntaxError: Unexpected token L in JSON at position 0    
    at JSON.parse (<anonymous>)
    at Pipe.channel.onread (internal/child_process.js:471:28)

Hello Guys,

I had found a lot of other issues/questions like this here and any where else, but no of them includes "Unhandled error in debug adapter". I had tried a lot of workflows, but nothing worked.

Short Introduction:

OS: Windows 64x

IDE: VS Code (version: 1.25.1 / launch.json see below)

vscode-Plugin: React Native Tools (version: 0.6.12)

Language/Framework: React-Native

(React-version: 16.4.1 /RN-version 0.55.4 / cli-version: 2.0.1)

Project: Android App (iOS followed later)

Output of React-Native: Run android Installing APK 'app-debug.apk' was successful.

Output of React-Native: Starting custom debugger by executing: echo A debugger is not needed: "[project-location]" "[project-location].vscode"

Starting App with react-native run-android via terminal still working.

Try following troubleshooting steps:

Existing project is to large to show it here and dosn't exist in a public repo.

launch.json - I'm using "Debug Android"

{    
    "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 iOS",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "ios",
            "sourceMaps": true,
            "outDir": "${workspaceRoot}/.vscode/.react"
        },
        {
            "name": "Attach to packager",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "attach",
            "sourceMaps": true,
            "outDir": "${workspaceRoot}/.vscode/.react"
        },
        {
            "name": "Debug in Exponent",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "exponent",
            "sourceMaps": true,
            "outDir": "${workspaceRoot}/.vscode/.react"
        }
    ]
}

I don't know where the problem is located:

Logcat prints only [INFO] no Warnings and no Errors.

Want to debug project with debug terminal of vscode, because debugging with chrome doesn't work with breakpoints.

I'm very new at working with vscode and RN, please explain possible solutions a little bit more detailed.

Thanks in advance.

Chris

Upvotes: 4

Views: 1299

Answers (1)

Grey Haven
Grey Haven

Reputation: 380

The error is in the vscode-react-native extension. There's already been a pull request made to fix this, but if you're feeling adventurous, go to your vscode extensions folder, open the vscode-react-native folder, go to src/debugger/forkedAppWorker.js and replace the following lines:

const nodeArgs = [`--inspect=${port}`, "--debug-brk", scriptToRunPath]; 

with

const nodeArgs = [`--inspect=${port}`, "--debug-brk"];

and

this.debuggeeProcess = child_process.spawn("node", nodeArgs, { 
    stdio: ["pipe", "pipe", "pipe", "ipc"], 
}) 

with

this.debuggeeProcess = child_process.fork(scriptToRunPath, nodeArgs) 

For more details see the actual file change log (don't worry about it being .ts vs .js, and don't worry about the other two files being changed).

Upvotes: 4

Related Questions