r
r
react-juce
Search…
Debugging with Duktape
(Because console.log() isn't always enough)
Note, there are known issues debugging on Windows. See Known Issues
JS debugging support for React-JUCE/Duktape is available via Visual Studio Code using the Duktape Debugger extension. Currently this is the only debug client known to support the use of source maps with Duktape. If you do become aware of other Duktape debug clients that may work well with React-JUCE, please open an issue with details for us to investigate.
React-JUCE provides an implementation of the Duktape debugging interface via EcmascriptEngine::debuggerAttach and EcmascriptEngine::debuggerDetach.
If you are using the ReactApplicationRoot class to host your React app/ui then you can enjoy a debugging experience similar to that of React Native.
In debug builds with JUCE_DEBUG defined, ensure your editor has focus and use the CTRL-d/CMD-d command to trigger a call to EcmascriptEngine::debuggerAttach. This command blocks the UI and awaits connection from a debug client. You can then attach your debugger, continue execution and set breakpoints etc.
To configure the Duktape debugger extension for use with React-JUCE, you will need to do the following:
    Download/Add the Duktape debugger extension.
    Ensure you have compiled React-JUCE and your application/plugin in debug mode (with JUCE_DEBUG defined).
    Add a launch configuration for debugging your UI.
An example launch configuration for use with the GainPlugin example project is provided below. Note that localRoot points to the root workspaceFolder. In this case we assume workspaceFolder to be examples/GainPlugin/jsui. The outDir entry points to the build directory containing the compiled JS bundle you wish to debug. This outDir directory should also contain the bundle's associated source map.
1
{
2
"version": "0.2.0",
3
"configurations": [
4
{
5
"name": "JSUI Debug Attach",
6
"type": "duk",
7
"request": "attach",
8
"address": "localhost",
9
"port": 9091,
10
"localRoot": "${workspaceFolder}",
11
"sourceMaps": true,
12
"outDir": "${workspaceFolder}/build/js",
13
"stopOnEntry": false,
14
"debugLog": false
15
}
16
]
17
}
Copied!
To ensure debugging works reliably, you need to ensure your source map has been generated by webpack using devtool. The following option should be added to the output key in your webpack config:
devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]'
You also need to ensure that your bundle is not minified, this can be achieved by building your JS bundle with webpack --mode=development. In the case of the GainPlugin example this can be achieved by running npm run start in GainPlugin/jsui.
The webpack.config.js template provided by React-JUCE enables all of this for you. See: Starting a new Project for a project template setup which includes debugger support. Project template files are available under react-juce/packages/react-juce/template.
Example webpack.config.js:
1
module.exports = {
2
entry: './src/index.js',
3
// This is the section you care about for debugging.
4
output: {
5
path: __dirname + '/build/js',
6
filename: 'main.js',
7
sourceMapFilename: "[file].map",
8
devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]'
9
},
10
devtool: "source-map",
11
module: {
12
rules: [
13
{
14
test: /\.(js|jsx)$/,
15
exclude: /node_modules/,
16
use: ['babel-loader']
17
},
18
{
19
test: /\.svg$/,
20
exclude: /node_modules/,
21
use: ['svg-inline-loader']
22
},
23
{
24
test: /\.(png|jpeg|jpg|gif)$/,
25
use: [
26
{
27
loader: 'url-loader',
28
options: {
29
limit: true,
30
esModule: false
31
}
32
}
33
]
34
}
35
]
36
},
37
}
Copied!
To test debugging support using the GainPlugin example do the following:
    Open the GainPlugin/jsui directory in Visual Studio Code.
    Add the launch.json configuration from above to your .vscode directory under GainPlugin/jsui.
    Run npm run start in the jsui directory
    Start the standalone plugin app in your IDE (i.e. Visual Studio/Xcode)
    Give the GainPlugin's UI/PluginEditor focus and hit CTRL-d (Win) / CMD-d (Mac)
    Start the JSUI Debug Attach launch task from the VSCode debugger menu.
    Set some breakpoints, profit!

Known Issues

    Debugging support is currently experimental and issues may occur from time to time whilst we refine the experience.
    At present there are some issues debugging duktape under Windows. The vscode-duktape-debug extension requires a patch to resolve source map entries, without this patch setting breakpoints in source files fails. To obtain a version of the extension with this patch you can fetch https://github.com/JoshMarler/vscode-duktape-debug/tree/topic/fix-windows-debug-blueprint. To use this version of the extension run npm install in the vscode-duktape-debug root followed by npm run compile. You can then copy the contents of vscode-duktape-debug/dist to your vscode extensions directory which is usually under .vscode in your home folder. Copy the contents of vscode-duktape-debug/dist to .vscode/extensions/haroldbrenes.duk-debug-0.5.6. There are issues attaching the debugger with breakpoints already set in vscode on Windows. You will need to attach the debugger and then set breakpoints once attached.

Acknowledgements

Thanks to harold-b for his excellent extension.
Last modified 7mo ago