Skip to content

Debug a transpiled ActionScript project in Visual Studio Code with Node.js

Josh Tynjala edited this page Feb 5, 2024 · 36 revisions
  1. Create a new ActionScript project that targets Node.js.

  2. In your project's asconfig.json, specify the source-map compiler option.

    "compilerOptions": {
    	"source-map": true
    }

    This will allow you to debug using the original .as files instead of the generated .js files.

  3. In Visual Studio Code, open the Run menu and select Add Configuration….

  4. It will ask you to select an environment. Select Node.js.

  5. Modify the program field, and add the cwd and outFiles fields in the Node.js launch configuration.

    {
    	"type": "node",
    	"request": "launch",
    	"name": "Launch Program",
    	"skipFiles": [
    		"<node_internals>/**"
    	],
    	"program": "${workspaceFolder}/bin/js-debug/index.js",
    	"cwd": "${workspaceRoot}/bin/js-debug",
    	"outFiles": [
    		"${workspaceRoot}/bin/js-debug/**/*.js"
    	]
    }
  6. Run the build task with Ctrl+Shift+B (or Command+Shift+B on macOS).

  7. Open Visual Studio Code's Run menu, and select Start Debugging. Alternatively, use the F5 keyboard shortcut to start debugging.

Build automatically before debugging

Instead of building manually with Ctrl+Shift+B, you can configure launch.json to build your project automatically when start debugging in Visual Studio Code. By setting the preLaunchTask field in launch.json to the name of one of your workspace's tasks, it will automatically run that task before the debugger is launched.

Warning: If you're compiling debug builds using the Quick Compile & Debug command, DO NOT use preLaunchTask. It will cause your project to build twice before starting the debugger, which won't be very "quick" at all! 😄

If you have a default build task configured, the preLaunchTask field in launch.json should contain the ${defaultBuildTask} token:

"preLaunchTask": "${defaultBuildTask}"

If you prefer, you can use the exact name of any of the built-in tasks provided by the ActionScript & MXML extension:

"preLaunchTask": "ActionScript: compile debug - asconfig.json"

You can find the complete list of tasks that are available in your workspace when you go to the Terminal menu and choose Run Task....

Further Reading

Clone this wiki locally