Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue] [Cordova Tool] Unable to debug with error: "Path must be string. Received null" after upgrade VS Code from 0.10.9 to 0.1010 #48

Closed
saravmajestic opened this issue Mar 6, 2016 · 24 comments
Assignees
Milestone

Comments

@saravmajestic
Copy link

I am getting the error [cordova-debug-adapter] TypeError: Path must be string. Received null when trying to debug my phonegap app using "Cordova tools".
Steps:

Installed VSCode Version 0.10.9 (0.10.9)
installed cordova extension from extensions gallery
selected Cordova from debug configuration and used default launch.json
clicked 'Run Android on emulator' Got the error as above.

I tried to add the workaround as mentioned in microsoft/vscode#3625
I tried to set sourceMaps as false and "outDir": "${workspaceRoot}" , but still getting same error.

I don't know which sourcemaps I have to specify as mentioned in the workaround. I am using Mac 10.10.5

Screenshot as below:
screen shot 2016-03-06 at 5 46 28 pm

@DickvdBrink
Copy link

Same issue here (with the insider build)

@MSLaguana
Copy link
Member

What version of node do you have installed? Looks like this might be to do with a change in node 5.7

@saravmajestic
Copy link
Author

My Node version is pretty old 0.10.32. Should I upgrade to latest?

@MSLaguana MSLaguana added the bug label Mar 7, 2016
@MSLaguana MSLaguana self-assigned this Mar 7, 2016
@MSLaguana
Copy link
Member

That is quite old, but shouldn't be related to this particular issue then. I'll investigate further.

@digeff
Copy link
Contributor

digeff commented Mar 7, 2016

@saravmajestic Could you please try:

  1. Setting sourceMaps: false and deleting the outDir key
  2. Setting sourceMaps: true and "outDir": "${workspaceRoot}"
  3. Setting sourceMaps: true and "outDir": "${workspaceRoot}/www" or whatever is the path to your index.html

@saravmajestic
Copy link
Author

@digeff I tried all these combinations now and still getting the error.

My phonegap version is 5.3.9. I will try to generate a new cordova project and try this out. In the meantime, let me know if you guys have any other work around

@MSLaguana
Copy link
Member

For a workaround, you should be able to specify "sourceRoot": "${workspaceRoot}/www" I believe. If that does fix it, please let us know and we'll put in a proper fix.

@MSLaguana
Copy link
Member

Looks like I may have been mistaken, and that value comes from the webview running the app, not from the launch.json.

I still haven't been able to reproduce the issue locally, but if you are willing to help us debug I can walk you through adding some extra logging so we can track down where the issue is:

  1. Go to ~/.vscode/extensions/vsmobile.cordova-tools-1.0.3/out/debugger, and then make some changes to adapter/sourceMaps/pathUtilities.js and adapter/sourceMaps/sourceMaps.js. After var Path = require('path'); add the following:

    function isAbs(s) {
      console.info(new Error().stack);
      console.info(s);
      return Path.isAbsolute(s);
    }
    
  2. In those files, find and replace Path.isAbsolute with isAbs

  3. Go to webkit/utilities.js and make a similar change, but use path.isAbsolute instead of Path.isAbsolute

  4. go back to ~/.vscode/extensions/vsmobile.cordova-tools-1.0.3/out/src/debugger and run node debugCordova.js --server=9955. This will run the debug adapter in server mode, and you'll be able to see its console output.

  5. Open up your project in vscode, and in your launch.json at the top level add "debugServer": 9955,

  6. Try to launch your project and trigger the bug

  7. Include any relevant output from the debug adapter we ran in step 4

I suspect that it is these isAbsolute calls that are causing the issue, but if not we still may get some useful output from the console.

@saravmajestic
Copy link
Author

@MSLaguana , thanks for detailed steps. I have tried to run debug server and I got this below error:

`node debugCordova.js --server=9955
waiting for v8 protocol on port 9955

accepted connection from client

/Users/saravanan/.vscode/extensions/vsmobile.cordova-tools-1.0.3/out/debugger/common/v8Protocol.js:52
this._pendingRequests = new Map();
^
ReferenceError: Map is not defined
at CordovaDebugSession.V8Protocol (/Users/saravanan/.vscode/extensions/vsmobile.cordova-tools-1.0.3/out/debugger/common/v8Protocol.js:52:37)`

Since my node version is old, Map is not available yet. I will see if I can inject it somehow and check.

@MSLaguana
Copy link
Member

I should have realized this would happen after you mentioned your older node version. If you could try to get node 4.X and use that, it should match what vscode uses more closely. If you don't want to update node system wide, you could consider nvm for managing multiple versions of node, or you could download the standalone binaries at https://nodejs.org/dist/v4.3.2/node-v4.3.2-darwin-x64.tar.gz and directly reference the node binary from that.

@saravmajestic
Copy link
Author

@MSLaguana , thanks for the tips

I tried these workarounds:

  • installed nvm and installed node 5.7.1, made this version as default using this command nvm alias default 5.7.1
  • Ran my existing project, without any changes you mentioned above with fresh version of cordova tools. Got the same error :(
  • Ran again with the changes you mentioned, I didnt get any logs while running. It just said 'process exit. Not for server instance' :(
  • created new cordova project and added android platform. Tried to run the debugger for 'Run Android device' and 'Run Android on emulator'. Still error :(

Is there anything else I can do to get some more logs?

@burtonsmith
Copy link

I am also having the same problem. I was using it previously without an issue, but it started after I installed the latest update for VS Code yesterday.

@DickvdBrink
Copy link

I added some logging with the steps above (but I changed them a bit ;) This is the result:

workspaceRoot: undefined
{ '0': undefined, '1': 'config.xml' }
Error
    at Object.path.join (C:\Users\dvdbrink\.vscode\extensions\vsmobile.cordova-tools-1.0.1\out\src\debugger\debugCordova.js:11:22)
    at Object.path.join (C:\Users\dvdbrink\.vscode\extensions\vsmobile.cordova-tools-1.0.1\out\src\debugger\cordovaDebugAdapter.js:17:21)
    at Object.path.join (C:\Users\dvdbrink\.vscode\extensions\vsmobile.cordova-tools-1.0.1\out\src\debugger\cordovaIosDeviceLauncher.js:14:21)
    at Object.path.join (C:\Users\dvdbrink\.vscode\extensions\vsmobile.cordova-tools-1.0.1\out\debugger\webkit\utilities.js:19:21)
    at Object.path.join (C:\Users\dvdbrink\.vscode\extensions\vsmobile.cordova-tools-1.0.1\out\src\utils\cordovaProjectHelper.js:8:21)
    at Object.path.join (C:\Users\dvdbrink\.vscode\extensions\vsmobile.cordova-tools-1.0.1\out\src\utils\telemetry.js:26:21)
    at Object.path.join (C:\Users\dvdbrink\.vscode\extensions\vsmobile.cordova-tools-1.0.1\out\src\debugger\cordovaPathTransformer.js:10:21)
    at Object.Path.join (C:\Users\dvdbrink\.vscode\extensions\vsmobile.cordova-tools-1.0.1\out\debugger\adapter\sourceMaps\sourceMaps.js:15:21)
    at Object.Path.join (C:\Users\dvdbrink\.vscode\extensions\vsmobile.cordova-tools-1.0.1\out\debugger\adapter\sourceMaps\pathUtilities.js:12:21)
    at Function.CordovaProjectHelper.getCordovaProjectRoot (C:\Users\dvdbrink\.vscode\extensions\vsmobile.cordova-tools-1.0.1\out\src\utils\cordovaProjectHelper.js:88:54)

In the CordovaDebugAdapter.prototype.launch link the launchArgs.cwd is empty which is causing the crash

This is what lauchArgs contains:

{ name: 'Run Android on device',
  type: 'cordova',
  request: 'launch',
  platform: 'android',
  target: 'device',
  port: 9222,
  sourceMaps: true,
  debugServer: 9955 
}

edit VSCode 0.10.10
*edit 2: *
So after adding "cwd": "${cwd}" to my configuration it worked :)

@burtonsmith
Copy link

Where did you add it exactly? I have a presentation on this this afternoon and would love to have this working.

@DickvdBrink
Copy link

@burtonsmith in the launch.json you have the configurations section. You need to add them to all of them but below you can find the first two examples

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Run Android on device",
"cwd": "${cwd}",
            "type": "cordova",
            "request": "launch",
            "platform": "android",
            "target": "device",
            "port": 9222,
            "sourceMaps": true
        },
        {
            "name": "Run iOS on device",
            "type": "cordova",
"cwd": "${cwd}",
            "request": "launch",
            "platform": "ios",
            "target": "device",
            "port": 9220,
            "sourceMaps": true
        },

I did align them on the left on purpose so you could see :)

@burtonsmith
Copy link

You, sir, are awesome! Thank you @DickvdBrink! This is a great workaround.

@saravmajestic
Copy link
Author

@DickvdBrink awesome. This is working now. Thanks a lot!

@DickvdBrink
Copy link

I might create a PR with a fix tonight if @MSLaguana doesn't beat me to it :)

@shreyashag
Copy link

Had the same problem, adding
"cwd": "${cwd}"
into all the configurations fixed it.

Thanks @DickvdBrink .
Cheers

@ghost ghost changed the title "Path must be string. Received null" error when attempting to start debugger [Issue] [Cordova Tool] Unable to debug with error: "Path must be string. Received null" after upgrade VS Code from 0.10.9 to 0.1010 Mar 8, 2016
@MSLaguana
Copy link
Member

Thanks a lot for investigating @DickvdBrink ! It seems that in the latest vscode the contract with debug adapters changed. I'll create a fix for new projects, but for anyone hitting this issue, the fix is as above: adding "cwd": "${workspaceRoot}" or similar to all your cordova launch configurations in launch.json

@MSLaguana
Copy link
Member

This will be fixed for new projects in the next release, until then I'll leave this issue open so anyone else hitting it can find it easily.

@ghost ghost added this to the v1.0.4 milestone Mar 8, 2016
@ghost
Copy link

ghost commented Mar 9, 2016

A new version of the extension was pushed to the marketplace which addresses this issue. After updating the extension existing projects will need to either include cwd attribute for each configuration as described previously ("cwd": "${workspaceRoot}") or delete the generated launch.json (if you haven't modified it) so that it can be regenerated correctly.

@ghost ghost closed this as completed Mar 9, 2016
@jagansai
Copy link

jagansai commented Apr 9, 2016

I still get the error even with the latest launch.json file.

error
error

@aualdrich
Copy link

Note I got this error when I deleted the contents of the android and ios folders but left the root "android" and "ios" platform folders intact. Deleting the actual folders fixed it.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants