Rebuilding node-inspector for Electron v1.3.0
Introduction
Debugging of JavaScript code in the main Electron process is usually done with the help of the
node-inspector NodeJS module, which needs to be loaded in an Electron process
in order to access code and resources within ASAR files. However, node-inspector has two
dependencies that are native Node modules (v8-debug and v8-profiler),
which must be rebuilt to target the Node runtime embedded in Electron. The Electron docs show one
way to rebuild these modules:
|
|
Unfortunately as of Electron v1.3.0 rebuilding of the v8-profiler module will fail due to missing
SetHiddenValue and GetHiddenValue methods in v8::Object. Electron ships with a newer version
of V8 than NodeJS v6, and these particular methods were removed from recent versions of the V8 API.
Eventually NodeJS will upgrade to the newer V8 API, NAN will be updated accordingly, and the
v8-profiler module will be updated to address the breaking changes, but until then you’re going
to have to install a modified version of the v8-profiler module that works with Electron.
Workaround
Replacing the original v8-profiler module with the modified version is easy,
but locking in the replacement so that you don’t have to redo it every time you checkout a fresh
copy of your project is a bit more finicky. Follow the steps below to lock in the correct version
of the module, note that the first step assumes the current working directory is the directory
containing your package.json.
-
Replace the
v8-profilermodule innode-inspector:123cd node_modules/node-inspectornpm install enlight/v8-profiler#v5.6.5-electron-v1.3 --savecd ../.. -
Now there’s probably a redundant copy of the
v8-profiler, remove it withnpm prune. WARNING: This will clear out modules innode_modulesthat aren’t referenced in yourpackage.json. -
Use the NPM
shrinkwrapcommand to lock in the modifiedv8-profilermodule:1npm shrinkwrap --devAssuming no errors occured
npm-shrinkwrap.jsonwill be generated in the directory containing yourpackage.json. If errors were encountered you will need to clear out any modules innode_modulesthat aren’t referenced inpackage.jsonand then try again. Oncenpm-shrinkwrap.jsonhas been generated open it up and remove everything but thev8-profilerpackage info, the following is all that should be left:123456789101112131415161718{"name": "myapp","version": "1.0.0","dependencies": {"node-inspector": {"version": "0.12.8","from": "node-inspector@>=0.12.8 <0.13.0","resolved": "https://registry.npmjs.org/node-inspector/-/node-inspector-0.12.8.tgz","dependencies": {"v8-profiler": {"version": "5.6.5","from": "enlight/v8-profiler#v5.6.5-electron-v1.3","resolved": "git://github.com/enlight/v8-profiler.git#607f871af2acf85ca75c3297b67989961699d7f5"}}}}}Add
npm-shrinkwrap.jsonto source control so that the next time someone runsnpm installafter a fresh checkout NPM will install the correct version ofv8-profiler. -
Rebuild the
v8-profilerto target Electron using your method of choice.
You can probably cheat a bit and skip the first three steps above by creating npm-shrinkwrap.json
manually, deleting node_modules/node-inspector, and then running npm install. Don’t forget to
change the package name and version when you copy/paste the contents from step #3 into your
npm-shrinkwrap.json.