Skip to content

Instantly share code, notes, and snippets.

@nightire
Created May 17, 2018 11:21
Show Gist options
  • Star 36 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save nightire/38ad30167df55175853b20f025f46596 to your computer and use it in GitHub Desktop.
Save nightire/38ad30167df55175853b20f025f46596 to your computer and use it in GitHub Desktop.
How to debug an ember application with VS Code

Step 1: Launch Google Chrome with Remote Debugging support

  • windows: <path to chrome>/chrome.exe --remote-debugging-port=9222
  • macOS: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
  • linux: google-chrome --remote-debugging-port=9222

Step 2: Install "Debugger for Chrome" extension

Step 3: Setup your application

  1. Open your ember application, add a launch setting in .vscode/launch.json, here is an example:

    {
      "version": "0.2.0",
      "configurations": [
        {
          "type": "chrome",
          "request": "attach",
          "name": "Attach to Chrome",
          "port": 9222,
          "url": "http://localhost:4200/*",
          "webRoot": "${workspaceFolder}"
    	}
      ]
    }
  2. Enable inline source maps, open ember-cli-build.js file, add an entry like:

    babel: {
      sourceMaps: 'inline'
    }
  3. (Optional) If you're using typescript, you need to enable inline source maps in tsconfig.json as well, make sure these settings are correct:

    "inlineSourceMap": true,
    "inlineSources": true,

Step 4: Enjoy It!

Now, boot up your ember application, open it in the browser, then head back to VS Code and hit f5 key. That's it; you should see something like below:

image

@benedikt-buchert
Copy link

benedikt-buchert commented Oct 6, 2018

It worked for me only with adding sourcemaps path overrides:

"sourceMapPathOverrides": {
    "myappname/*": "${workspaceRoot}/app/*"
},

@nerdybeast
Copy link

nerdybeast commented Mar 29, 2019

So I have only been ever to debug ember apps by using "launch" in vscode which is a pain because you have to reopen the browser console everytime and it's a huge waste of time. BUT FINALLY today I got ATTACH working!

I'm on a Windows machine BTW using Windows 10.

My "attach" config looks like:

{
	"type": "chrome", //Requires the "Debugger for Chrome" vscode extension
	"request": "attach",
	"name": "attach", //Can be whatever name you want to give this config
	"port": 9222, //This needs to be the same port as the remote debugging port that you launch Chrome with
	"urlFilter": "http://localhost:4200*",
	"webRoot": "${workspaceFolder}",
	"sourceMapPathOverrides": {
		//"myappname" is from the environment.js "modulePrefix" property.
		"myappname/*": "${workspaceFolder}/app/*"
	}
}

Then I modified the shortcut to Chrome on my machine to add "--remote-debugging-port=9222"
NOTE: I had to wrap this in double quotes to get it to work for me...

So the "Target" property for me looks like:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "--remote-debugging-port=9222"

image

Then in ember-cli-build.js add:

babel: {
    sourceMaps: 'inline'
}

That looks like:

module.exports = function(defaults) {
  let app = new EmberApp(defaults, {
    babel: {
      sourceMaps: 'inline'
    }
  });

  return app.toTree();
};

All this and my breakpoints in vscode hit the correct source:
image

👊

@bgolla
Copy link

bgolla commented Jun 9, 2021

It worked for me only with adding sourcemaps path overrides:

"sourceMapPathOverrides": {
    "myappname/*": "${workspaceRoot}/app/*"
},

Thanks, I could also map tests and mirage.

 "sourceMapPathOverrides": {
        "appname/tests/*": "${workspaceFolder}/tests/*",
        "appname/mirage/*": "${workspaceFolder}/mirage/*",
        "appname/*": "${workspaceFolder}/app/*"
      }

@yshteinm
Copy link

yshteinm commented Jun 17, 2022

Cannot make it work. Breakpoint shows as Unbound and app stops in "dist/assets/finalfile.js"
Below is my configs. Any advice?

{
  "configurations": [
    {
      "type": "chrome",
      "request": "attach",
      "name": "attach",
      "port": 9222,
      "urlFilter": "http://localhost:4200*",
      "webRoot": "${workspaceFolder}",
      "sourceMapPathOverrides": {
        // "emberjs-tutorial/*": "${workspaceRoot}/app/*",
        "emberjs-tutorial/*": "${workspaceFolder}/app/*"
      }
    },    

    
  ]
}
module.exports = function (defaults) {
  let app = new EmberApp(defaults, {
    // Add options here
    sassOptions: {
      extension: 'scss',
    },
    babel: {
      sourceMaps: 'inline'
    },
    // sourcemaps: { enabled: true, extensions: ['js'] }
  });

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment