I want to require a module from node_modules and I want to bundle it (for test purposes), but Webpack behaves as if it is added to externals.
// no externals or any plugin used
let config = {
mode: 'none',
target: 'node',
entry: {
output: `/example.js`,
},
resolve: {
extensions: ['.js'],
},
output: {
path: './dist',
},
};
// exampl.js
require('path')
// dist/output.js
require('path');
Expected behavior
the node module path
to be bundled
actual behavior
Webpack keep require('path');
This is by design. When you set
target: 'node'
in webpack config, webpack will not bundle the built-ins module of Node.js.path
is a built-in module of Node.js, it doesn't come from thenode_modules
directory.See targets