Can't require('electron') successfully when build and run vscode source code

Viewed 381

I'm running vscode from source code and following the steps:

  1. download vscode source code (version:1.63.0)
 "name": "code-oss-dev",
 "version": "1.63.0",
 "distro": "1aa3ab55b3cceca22ca6d647dc0095d562d23c8d",
  1. run yarn to install packages.
  2. run yarn watch to build and finished successfully.
......
[watch-extensions] [23:54:02] Finished webpacking extension media markdown-language-features with 0 errors.
[watch-extensions] [23:54:02] Finished webpacking extension media simple-browser with 0 errors.
[watch-extensions] [23:54:14] Finished compilation extensions with 0 errors after 44266 ms
[watch-client    ] [23:55:24] Finished compilation with 0 errors after 111430 ms
  1. run ./scripts/code.sh to launch but failed.
localhost:vscode-main$ ./scripts/code.sh 
yarn run v1.22.10
$ node build/lib/electron
✨  Done in 3.27s.
[00:00:37] Syncronizing built-in extensions...
[00:00:37] You can manage built-in extensions with the --builtin flag
[00:00:38] Downloading extension: ms-vscode.references-view@0.0.81 ...
[00:00:38] Downloading extension: ms-vscode.js-debug-companion@1.0.15 ...
[00:00:38] Downloading extension: ms-vscode.js-debug@1.62.0 ...
[00:00:38] Downloading extension: ms-vscode.vscode-js-profile-table@0.0.18 ...
[00:00:38] [marketplace] ms-vscode.vscode-js-profile-table ✔︎
[00:00:38] [marketplace] ms-vscode.references-view ✔︎
[00:00:38] [marketplace] ms-vscode.js-debug-companion ✔︎
[00:00:39] [marketplace] ms-vscode.js-debug ✔︎
/Users/xxx/vscode-main/out/main.js:28
app.allowRendererProcessReuse = false;
                              ^

TypeError: Cannot set property 'allowRendererProcessReuse' of undefined
    at Object.<anonymous> (/Users/xxx/vscode-main/out/main.js:28:31)
    at Module._compile (internal/modules/cjs/loader.js:1078:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1108:10)
    at Module.load (internal/modules/cjs/loader.js:935:32)
    at Module._load (internal/modules/cjs/loader.js:776:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

relative code in main.js is

const { app, protocol, crashReporter } = require('electron');

app.allowRendererProcessReuse = false;

I add a log

......
const { app, protocol, crashReporter } = require('electron');
const abc = require('electron'); //added
console.log(abc); //added
console.log('isString?', typeof abc === 'string'); //added
app.allowRendererProcessReuse = false;

the result is

localhost:vscode-main$ ./scripts/code.sh 
yarn run v1.22.10
$ node build/lib/electron
✨  Done in 2.07s.
[00:11:51] Syncronizing built-in extensions...
[00:11:51] You can manage built-in extensions with the --builtin flag
[00:11:51] [marketplace] ms-vscode.references-view@0.0.81 ✔︎
[00:11:51] [marketplace] ms-vscode.js-debug-companion@1.0.15 ✔︎
[00:11:51] [marketplace] ms-vscode.js-debug@1.62.0 ✔︎
[00:11:51] [marketplace] ms-vscode.vscode-js-profile-table@0.0.18 ✔︎
/Users/xxx/vscode-main/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron
isString? true
/Users/xxx/vscode-main/out/main.js:30
app.allowRendererProcessReuse = false;
                              ^

TypeError: Cannot set property 'allowRendererProcessReuse' of undefined
    at Object.<anonymous> (/Users/xxx/vscode-main/out/main.js:30:31)

why require('electron') is parsed into a string here?

1 Answers

Problem resolved.

After executing command env, I find there is a environment variable ELECTRON_RUN_AS_NODE=1. (I have never set this variable...)

execute unset ELECTRON_RUN_AS_NODE, and confirm the variable does not exist anymore.

require('electron') can work now.

Related