Skip to content

Commit

Permalink
Avoid relying on Node’s internals
Browse files Browse the repository at this point in the history
`process.binding()` is not a public API, and should
not be used.

Luckily, Node recently introduced an API that does
exactly what Webpack needs:
https://nodejs.org/api/modules.html#modules_module_builtinmodules

So use that instead and keep the old path as a fallback.
  • Loading branch information
addaleax committed Jan 27, 2018
1 parent 33f518b commit e4375f8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/node/NodeTargetPlugin.js
Expand Up @@ -6,9 +6,11 @@

const ExternalsPlugin = require("../ExternalsPlugin");

const builtins = require("module").builtinModules || Object.keys(process.binding("natives"));

This comment has been minimized.

Copy link
@spion-h4

spion-h4 Feb 15, 2018

This doesn't work, instead it generates

ModuleNotFoundError: Module not found: Error: Can't resolve 'module' in '/path/to/project/node_modules/webpack/lib/node'

class NodeTargetPlugin {
apply(compiler) {
new ExternalsPlugin("commonjs", Object.keys(process.binding("natives"))).apply(compiler);
new ExternalsPlugin("commonjs", builtins).apply(compiler);
}
}

Expand Down

0 comments on commit e4375f8

Please sign in to comment.