question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

webpack does not include node_modules dependency!!

See original GitHub issue

Do 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:closed
  • Created 4 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, Mar 11, 2020

It is not impact the performance

1reaction
alexander-akaitcommented, Mar 11, 2020

Just do not bundle server code and update server code and node_modules to cloud

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does Webpack include all dependent node modules along ...
Technically speaking, React is a dev dependency in a bundled app, because you don't need it in production unless you also do server...
Read more >
A Guide to Managing Webpack Dependencies - Toptal
If we want to include modules from externally hosted scripts, we need to define them in the configuration. Otherwise, Webpack cannot generate the...
Read more >
Dependency Management - webpack
A context module is generated. It contains references to all modules in that directory that can be required with a request matching the...
Read more >
Using node modules with njs - Nginx.org
This can be solved by merging all the interdependent code into a single file. Tools like browserify or webpack accept an entire project...
Read more >
How to transpile ES modules with webpack and Node.js
Webpack is a build tool that helps bundle our code and its dependencies into a single JavaScript file. We can also say that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found