When I use webpack to compile on node, require will be replaced by __webpack_require__, but __webpack_require__ can not support dynamic require modules, which will result in searching package.json failed.
Webpack is for packaging web apps ; but module-alias is specifically built for server-side node projects. So you really shouldn't be using it in a project that uses webpack.
When I use webpack to compile on node,
require
will be replaced by__webpack_require__
, but__webpack_require__
can not support dynamicrequire
modules, which will result in searching package.json failed.Discussion about dynamic require on node with webpack: https://github.com/webpack/webpack/issues/4175
current webpack output file:
forbid using __webpack_require__: