webpack does not include node_modules dependency!!
See original GitHub issueDo you want to request a feature or report a bug?
bug
What is the current behaviour?
When there is no node_modules folder in the current directory
when I build my typescript node project and run node dist/index.js
it throws all shorts of error for eg:
cannot find module 'graphql-import'
cannot find module 'express'
If the current behaviour is a bug, please provide the steps to reproduce.
my webpack.prod.js file:
const path = require("path")
const nodeExternals = require("webpack-node-externals")
const Dotenv = require("dotenv-webpack")
module.exports = {
entry: "./src/server.ts",
externals: [nodeExternals()],
mode: "production",
devtool: "inline-source-map",
target: "node",
resolve: {
extensions: [".ts", ".js"],
modules: [path.resolve("./node_modules"), path.resolve("./src")]
},
node: {
__dirname: false
},
output: {
filename: "index.js",
path: path.resolve(__dirname, "dist")
},
module: {
rules: [
{
test: /\.ts$/,
use: "ts-loader",
exclude: /node_modules/
}
]
},
plugins: [
new Dotenv({
path: "./.env"
})
]
}
my tsconfig.json file:
{
"compileOnSave": true,
"compilerOptions": {
"baseUrl": "src",
"outDir": "./dist/",
"skipLibCheck": true,
"sourceMap": true,
"noImplicitAny": true,
"module": "es6",
"target": "es5",
"allowJs": true,
"moduleResolution": "node",
"noUnusedLocals": false,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["es2016", "esnext.asynciterable"]
},
"exclude": ["node_modules"]
}
What is the expected behaviour?
expect to run my nodejs server smoothly and printing
🚀 Server is running on port: 4000
If this is a feature request, what is motivation or use case for changing the behaviour? No its not a feature request.
Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
Node version: 10.13.0 (i tried with 12.x.x too) webpack: 4.39.2 webpack-cli: 3.3.7 typescript: 3.5.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (8 by maintainers)

Top Related StackOverflow Question
It is not impact the performance
Just do not bundle server code and update server code and node_modules to cloud