How can I debug my Meteor app using the WebStorm IDE?
Asked Answered
P

6

17

Can anyone provide a short list of steps on how to connect a Meteor app to the WebStorm debugger please?

Peridot answered 7/2, 2013 at 12:26 Comment(2)
To debug meteor app in IDE, you can do following: youtrack.jetbrains.com/issue/WEB-6264#comment=27-445048Sino
WebStorm has had Meteor support for a few months now. @BenjaminRH, can you please remove the old comment? Thanks!Ireneirenic
I
24

WebStorm is the only IDE with native support for debugging Meteor server code - check this video. Even on Windows, debugging is very simple:

WebStorm 9+

Go to Run --> Debug --> Edit configurations... , click the plus sign, click "Meteor". You can add environment variable like ROOT_URL if you need to.


WebStorm older than 9

This answer is kept only for historical purposes. You should upgrade WebStorm.

On older WebStorms, you used to have to create a Node.js debugging configuration.

  • on the server, export the environment variable NODE_OPTIONS=--debug=47977. For instance,

    NODE_OPTIONS=--debug=47977 meteor  # Linux/Mac
    set NODE_OPTIONS=--debug=47977 & meteor`  # Windows
    
  • create a WebStorm/PhpStorm Run/Debug configuration using the port above (47977) and the server host. Leave 127.0.0.1 if you're debugging locally.

Run -> Run/Debug confioguration

  • in WebStorm, Run -> Debug <myapp>, or press Shift+F9. Make sure that you see "Connected to <your host> in the Debug panel

Now you can set breakpoints, have access to local variables etc.

For client debugging, just use the Chrome debugger, or Firebug.

Troubleshooting

  • Process disconnected unexpectedly - this happens when meteor restarts automatically because of lack of specific support for Meteor. Just Run -> Debug <myapp>, or press Shift+F9 again.

  • you can't connect to the server - make sure the firewall rules allow incoming connections to whatever port you chose for the Node.js debugger (47977 here).

Ireneirenic answered 5/2, 2014 at 7:36 Comment(5)
Just an extra note that the Share option in the run configuration is important too. I missed that one.Incantation
@Pie21: would you know what that option does? It has no tooltip and if I recall correctly, it didn't make a difference on my setup.Ireneirenic
@DanDascalescu: To be honest, even with the checkbox it still didn't catch break points for me, but it did at least say "connected". I didn't do any very rigorous testing, and it might have just been restarting the debugger that fixed the connection, but I assume it means that you can have multiple debuggers on the same port, or something. I'm the wrong person to ask; my comment was perhaps a bit of false confidence :).Incantation
Does not work for me, even with the share checkbox. I get "Cannot connect" in Variables. I'm remotely connecting to a Meteor 0.8.0.1 server and tried disabling firewall entirely.Pokelogan
Does not work for me with Meteor 0.9.3 and WebStorm 9 It says connecting to localhost, but never connects. Checked firewall to be off both on Windows and on linux/precise32/vagrantCoff
P
11

The other answers are now out of date. Don't add a Node.js debug configuration as described above, or bother with spyjs.

If you're using Webstorm 9.0, it's as simple as going to Run --> Debug --> Edit configurations... , click the plus, click "Meteor".

WebStorm may also ask you to install a browser add-on, but that's just for client-side debugging; just add a breakpoint in the server-side code and you'll see it works out of the box.

JetBrains have updated the video which was linked to in Dan Dascalescu's answer above, and it shows you the process I just described.

Pokelogan answered 25/1, 2015 at 6:30 Comment(0)
W
5

For applications using webpack:webpack, using WebStorm's Meteor debug profile did not seem to work.

My setup uses webpack:webpack v1.0.12, Meteor v1.3.0 and WebStorm 2016.1, but is likely to work with later versions (note that a fix for just this issue was released in v1.0.12, so earlier versions are likely not to work with this procedure).

Here is what I did in order to get it working:

  1. Create a webpack.json file at the project root.

    It should include the devtool config, which generates source maps that assist in debugging. The rest may be changed according to your specific setup.

    {
      "root": "src",
      "devServer": {
        "host": "localhost"
      },
      "devtool": "source-map"
    }
    
  2. Create a debug setup:

    Node.js Remote Debug, port 5858 (the port is configurable).

    remote node debug configuration

  3. Run meteor debug

    You may specify a port using --debug-port <port number>.

    See meteor help debug for the full details.

    meteor debug first run

  4. Connect WebStorm to the debugger

    • start the debugger click "debug"
    • the status message should indicate that it is connected. Scripts should available in the Scripts tab. the debug panel should state that it is connected
    • the server should be running in the console server should resume execution
  5. Hit your breakpoints and rejoice.

Wenz answered 31/3, 2016 at 12:26 Comment(0)
P
3

WebStorm 9 will have Meteor support. While WS 9 isn't released yet (as of Oct 7, 2014), there is an early access program for WS 9.

Read the JetBrains WebStorm blog which describes some of the Meteor support features and includes a brief video.

I'm new to Meteor, WebStorm (and JavaScript for that matter) and have been using the WS 9 EAP build 138.2406 for a couple of weeks. I can launch my project from within the IDE, set breakpoints, walk though code, inspect values, jump to definitions, and issue completions. It's quite helpful.

Pegg answered 7/10, 2014 at 20:1 Comment(0)
P
0

You can try spyjs plugin for Webstorm: http://blog.jetbrains.com/webstorm/2014/04/spy-js-webstorm-secret-service/

Pub answered 14/11, 2014 at 1:22 Comment(1)
SpyJS, while a useful too, does something else.Ireneirenic
D
0

There is a bug with old versions of Webstorm to debug server-side of Meteor 1.2.x. The latest version of Webstorm (11.0.3) released on Dec 24th, 2015 fixed it. Release notes can be found here: https://confluence.jetbrains.com/display/WI/WebStorm+143.1559.5+Release+Notes

I am now able to debug without any problem from Webstorm :)

Detainer answered 10/2, 2016 at 12:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.