You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that there will be an `import` statement in the output bundle.
634
634
635
+
This is useful when dependencies rely on Node.js built-in modules or require a CommonJS-style `require` function to preserve prototypes, which is necessary for functions like [`util.inherits`](https://nodejs.org/api/util.html#utilinheritsconstructor-superconstructor). Refer to [this issue](https://github.com/webpack/webpack.js.org/issues/7446) for more details.
636
+
637
+
For code that relies on prototype structures, like:
638
+
639
+
```js
640
+
functionChunkStream() {
641
+
Stream.call(this);
642
+
}
643
+
util.inherits(ChunkStream, Stream);
644
+
```
645
+
646
+
You can use `node-commonjs` to ensure that the prototype chain is preserved:
647
+
648
+
```js
649
+
const { builtinModules } =require('module');
650
+
651
+
module.exports= {
652
+
experiments: { outputModule:true },
653
+
externalsType:'node-commonjs',
654
+
externals: ({ request }, callback) => {
655
+
if (/^node:/.test(request) ||builtinModules.includes(request)) {
This setup keeps the prototype structure intact, resolving issues with Node.js built-ins.
677
+
635
678
### externalsType.promise
636
679
637
680
Specify the default type of externals as `'promise'`. Webpack will read the external as a global variable (similar to [`'var'`](#externalstypevar)) and `await` for it.
0 commit comments