Closed arthurdevv closed 2 years ago
You definitely cannot load native modules in webpack. I suggest adding node-pty
as an external module:
https://webpack.js.org/configuration/externals/
This will allow running in Electron with Node integration turned on.
When adding node-pty
as an external module, the webpack compiled successfully, but fails:
App threw an error during load
ReferenceError: node is not defined
at Object.node-pty (C:\Users\arthur\Desktop\Terminal\dist\main.js:21:18)
at __webpack_require__ (C:\Users\arthur\Desktop\Terminal\dist\main.js:45:41)
at C:\Users\arthur\Desktop\Terminal\dist\main.js:102:66
at C:\Users\arthur\Desktop\Terminal\dist\main.js:153:3
at Object.<anonymous> (C:\Users\arthur\Desktop\Terminal\dist\main.js:155:12)
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)
So I installed webpack-node-externals
and added it to the webpack:
const nodeExternals = require('webpack-node-externals');
module.exports = {
...
externals: [nodeExternals()],
...
};
it worked.
Edit:
I think the problem was that node-pty
was not as an external module, as @corwin-of-amber said. Thanks!
Great. FYI this could also work:
module.exports = {
...
externals: {
'node-pty': 'commonjs2 node-pty'
}
...
}
Via the string value option.
It is one of the less intuitive nooks of webpack, I have to admit.
Environment details
Issue description
When try to build it with webpack using babel-loader and node-loader fails:
Error logs