vscode-react-native icon indicating copy to clipboard operation
vscode-react-native copied to clipboard

No logs when attaching for react native.

Open auchenberg opened this issue 9 years ago • 12 comments

From @vettukal on September 20, 2017 13:1

I can't see any console.log output when attaching the debugger to chrome for the react-native.

  • VS Code Version: Version 1.16.1 (1.16.1)

Steps to reproduce:

  1. Launch chrome with command: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222

  2. in Launch.json the config is:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach",
            "type": "chrome",
            "request": "attach",
            "diagnosticLogging": true,
            "port": 9222,
            "url": "http://localhost:8081/debugger-ui",
            "webRoot": "${workspaceRoot}"
        }
    ]
}

  1. Attached the debugger.
  2. output in debug console as follows:
Verbose logs are written to:
/var/folders/c5/7q9p3jtd1h99nwlmdsvwfpyshmyx6r/T/vscode-chrome-debug.txt
OS: darwin x64
Adapter node: v7.9.0 x64
vscode-chrome-debug-core: 3.17.6
debugger-for-chrome: 3.2.1
Discovering targets via http://127.0.0.1:9222/json
Paths.scriptParsed: could not resolve http://localhost:8081/debugger-ui to a file under webRoot: /Users/16527/ios/dir2/myios-app. It may be external or served directly from the server's memory (and that's OK).
Target userAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36
.scripts
› VM84
› http://localhost:8081/debugger-ui

Just wanted to ask, how can I see the logs in VSCode and also add breakpoints. P.S: I have tried react-native-debugger. Unfortunately that doesnot work for me. I guess this may be easier to setup.

Copied from original issue: Microsoft/vscode-chrome-debug#505

auchenberg avatar Sep 20 '17 13:09 auchenberg

Our Chrome debugger doesn't support React Native. We have a dedicated project, https://github.com/Microsoft/vscode-react-native, for this.

auchenberg avatar Sep 20 '17 13:09 auchenberg

Hi @vettukal! Please try this extension for debugging react-native. And let me know if this works for you. Thanks!

itoys avatar Sep 20 '17 14:09 itoys

@iTOYS Trying react-native Extension.

  1. Launch.json
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "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"
        }
    ]
}
  1. Selecting Debug iOS and pressing play button. Output in Debug Console:
[vscode-react-native] Starting React Native Packager.
[vscode-react-native] Prewarming bundle cache. This may take a while ...
[vscode-react-native] Building and running application.
[vscode-react-native] Executing command: react-native run-ios --simulator
Scanning 716 folders for symlinks in /Users/16527/ios/dir2/myios-app/node_modules (5ms)
ENOENT: no such file or directory, uv_chdir
[Error] "Could not debug. Error while executing command 'react-native run-ios --simulator': Error while executing command 'react-native run-ios --simulator'"
  1. Now running the app from xcode and after starting the packager, I select "Attach to packager" and run play button. The app runs fine when its not in debug mode.
[vscode-react-native] Debugger ready. Enable remote debugging in app.
[vscode-react-native] Starting debugger app worker.
[vscode-react-native] Established a connection with the Proxy (Packager) to the React Native application 
  1. Now to enter debug mode, press CMD+D and select Debug remotely App fails to load. Debug Console output
[vscode-react-native] Debugger worker loaded runtime on port 35151

Error pops up the top. Output:

Ensure Node was launched with --inspect. Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the tar

vettukal avatar Sep 20 '17 14:09 vettukal

@vettukal What version of react-native do you use? Could you please run app in terminal with react-native run-ios --simulator and if it run, try attach Looks like that issue https://github.com/facebook/react-native/issues/11293

Also, could you please try react-native init app

itoys avatar Sep 21 '17 08:09 itoys

React native version: 0.46.3 react-native run-ios --simulator will give ENOENT: no such file or directory, uv_chdir error. I am trying this on an native app on which RN was added. Its not a pure RN app.

Will have to try react-native init and check whether it works on a new app or not.

vettukal avatar Sep 21 '17 11:09 vettukal

Hello @vettukal Any updates?

itoys avatar Oct 03 '17 15:10 itoys

@iTOYS I tried creating a new project as given in https://facebook.github.io/react-native/docs/getting-started.html.

and then followed the steps as mentioned in https://github.com/Microsoft/vscode-react-native/blob/master/doc/expo.md.

But debug in expo does not result in anything. There is not debug console output or anything. No error etc.

vettukal avatar Oct 03 '17 15:10 vettukal

Also I could not see any file as ${workspaceRoot}/.vscode/launchReactNative.js. Even after 'ejecting' it didn't work and didn't output anything.

vettukal avatar Oct 03 '17 15:10 vettukal

@vettukal ${workspaceRoot}/.vscode/launchReactNative.js doesn't need to exist - IIRC this entry was required to be specified due to some VSCode debug protocol limitation, when launch configuration must contain "program" property, but react-native debugger doesn't use it anyway. @iTOYS - we might want to revisit this to see if it's still required.

Regarding running app and attachning to packager - those two lines

[vscode-react-native] Debugger worker loaded runtime on port 35151
Ensure Node was launched with --inspect. Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the tar

are likely saying that Node failed to run bundled JS code perhaps because of some issues with JS which compiles fine but then crashes at load time. @vettukal can you double check that the app is running fine in debug mode without VSCode (i.e. in Chrome)?

For running CRNA app in Expo - @iTOYS, were you able to repro it?

vladimir-kotikov avatar Oct 05 '17 08:10 vladimir-kotikov

Yes the app was running fine in Chrome in debug mode.

On Thu, Oct 5, 2017 at 2:19 PM, Vladimir Kotikov [email protected] wrote:

@vettukal https://github.com/vettukal ${workspaceRoot}/.vscode/ launchReactNative.js doesn't need to exist - IIRC this entry was required to be specified due to some VSCode debug protocol limitation, when launch configuration must contain "program" property, but react-native debugger doesn't use it anyway. @iTOYS https://github.com/itoys - we might want to revisit this to see if it's still required.

Regarding running app and attachning to packager - those two lines

[vscode-react-native] Debugger worker loaded runtime on port 35151 Ensure Node was launched with --inspect. Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the tar

are likely saying that Node failed to run bundled JS code perhaps because of some issues with JS which compiles fine but then crashes at load time. @vettukal https://github.com/vettukal can you double check that the app is running fine in debug mode without VSCode (i.e. in Chrome)?

For running CRNA app in Expo - @iTOYS https://github.com/itoys, were you able to repro it?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode-react-native/issues/537#issuecomment-334401219, or mute the thread https://github.com/notifications/unsubscribe-auth/ABMGcBX7lcEqNwEc40aB9HhaJs_D2eRVks5spJg1gaJpZM4Pd4e1 .

vettukal avatar Oct 05 '17 10:10 vettukal

@vladimir-kotikov @vettukal I can't reproduce that. All works fine with CRNA app and [email protected]

Getting exponent dependecy.
Dependency not present. Installing it...
######### Making sure your project uses the correct dependencies for exponent. This may take a while... ##########
Checking if this is Expo app......
.......................
######### Starting Packager ##########
######### Executing command: react-native.cmd start --port 8081 --root .vscode --assetExts ttf ##########
Scanning 768 folders for symlinks in c:\projects\_test\CRNA\node_modules (26ms)
 ┌────────────────────────────────────────────────────────────────────────────┐ 
 │  Running packager on port 8081.                                            │ 
 │                                                                            │ 
 │  Keep this packager running while developing on any JS projects. Feel      │ 
 │  free to close this tab and run your own packager instance if you          │ 
 │  prefer.                                                                   │ 
 │                                                                            │ 
 │  https://github.com/facebook/react-native                                  │ 
 │                                                                            │ 
 └────────────────────────────────────────────────────────────────────────────┘ 
Looking for JS files in
   c:\projects\_test\CRNA
   c:\projects\_test\CRNA\.vscode 


React packager ready.

######### Packager started. ##########
"Warning: You are using npm version 5.3.0. There may be bugs in this version, use it at your own risk. We recommend version 4.6.1."
"Warning: You are using npm version 5.3.0. There may be bugs in this version, use it at your own risk. We recommend version 4.6.1."
Sucessfully ran `adb reverse`. Localhost urls should work on the connected Android device.Sucessfully ran `adb reverse`. Localhost urls should work on the connected Android device.Loading dependency graph, done.
"Warning: You are using npm version 5.3.0. There may be bugs in this version, use it at your own risk. We recommend version 4.6.1."
"Warning: You are using npm version 5.3.0. There may be bugs in this version, use it at your own risk. We recommend version 4.6.1."
Bundling `node_modules\react-native-scripts\build\bin\crna-entry.js`  [development, non-minified, hmr disabled]  100.0% (638/638), done.
Running application "main" with appParams: {"rootTag":1,"initialProps":{"exp":{"manifest":{"id":"@toys/CRNA","sdkVersion":"21.0.0","version":"0.1.0","packagerOpts":{"lanType":"ip","minify":false,"strict":false,"urlRandomness":"mb-gmy","hostType":"tunnel","urlType":"exp","dev":true},"mainModuleName":"./node_modules/react-native-scripts/build/bin/crna-entry","isVerified":true,"xde":true,"slug":"CRNA","debuggerHost":"packager.mb-gmy.toys.crna.exp.direct:80","developer":{"projectRoot":"c:\\projects\\_test\\CRNA","tool":null},"bundleUrl":"http://packager.mb-gmy.toys.crna.exp.direct:80/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=ios&dev=true&strict=false&minify=false&hot=false&assetPlugin=expo/tools/hashAssetFiles","env":{"EXPO_DEBUG":"true"},"name":"CRNA","logUrl":"http://mb-gmy.toys.crna.exp.direct:80/logs"},"appOwnership":"expo","initialUri":"exp://mb-gmy.toys.crna.exp.direct","shell":false}}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFFRunning application "main" with appParams: {"rootTag":1,"initialProps":{"exp":{"manifest":{"id":"@toys/CRNA","sdkVersion":"21.0.0","version":"0.1.0","packagerOpts":{"lanType":"ip","minify":false,"strict":false,"urlRandomness":"mb-gmy","hostType":"tunnel","urlType":"exp","dev":true},"mainModuleName":"./node_modules/react-native-scripts/build/bin/crna-entry","isVerified":true,"xde":true,"slug":"CRNA","debuggerHost":"packager.mb-gmy.toys.crna.exp.direct:80","developer":{"projectRoot":"c:\\projects\\_test\\CRNA","tool":null},"bundleUrl":"http://packager.mb-gmy.toys.crna.exp.direct:80/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=ios&dev=true&strict=false&minify=false&hot=false&assetPlugin=expo/tools/hashAssetFiles","env":{"EXPO_DEBUG":"true"},"name":"CRNA","logUrl":"http://mb-gmy.toys.crna.exp.direct:80/logs"},"appOwnership":"expo","initialUri":"exp://mb-gmy.toys.crna.exp.direct","shell":false}}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF

Tab with QR code has opened. upd. Application also works in Expo app on phone

itoys avatar Oct 05 '17 13:10 itoys

Dont' repro. Feel free to reopen this issue if you still have problem with it.

itoys avatar Nov 22 '17 12:11 itoys