Skip to content

Electron's module wrapper differs from modern Node's (includes "process" and "global") #8358

@ide

Description

@ide
  • Electron version: 1.4.11
  • Operating system: macOS 10.12.2

Expected behavior

I expected Electron to wrap JS modules in the same function wrapper as Node's. Electron defines an extra parameter ("process") which breaks code like const process = .... See Node's wrapper:

'(function (exports, require, module, __filename, __dirname) { '

https://github.com/nodejs/node/blob/0fb21df6e692bef9f55b9bfa876f3c59dc590332/lib/internal/bootstrap_node.js#L506

I tested with Node 6.0.0 & Node 7.4.0 and both use this wrapper.

Actual behavior

Electron uses a slightly different wrapper from its vendored copy of Node:

'(function (exports, require, module, __filename, __dirname, process, global) { '

https://github.com/electron/node/blob/811cfe3fcd360179d3dd436e3d80e1b045adf633/lib/internal/bootstrap_node.js#L489

How to reproduce

In a file loaded by Electron I have:

const child_process = require('child_process');
child_process.fork('./sample.js', [], {
    env: {
      ...process.env,
      ELECTRON_RUN_AS_NODE: 1,
    },
    silent: true,
});

and sample.js is:

'use strict';
const process = require('process');

and this results in the error: SyntaxError: Identifier 'process' has already been declared

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions