Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production build memory consumption #91

Closed
ntimo opened this issue Dec 20, 2020 · 6 comments
Closed

Production build memory consumption #91

ntimo opened this issue Dec 20, 2020 · 6 comments
Labels
bug Something isn't working pending on external library this issue is pending on another issue/PR of an external library

Comments

@ntimo
Copy link

ntimo commented Dec 20, 2020

Hey,
I just wanted to try to use codedoc but for some reason the build always fails for me.

Steps to reproduce:

  • docker run --rm -it node:lts bash
  • cd /opt/
  • npm i -g @codedoc/cli
  • codedoc init
  • codedoc build

build output:

root@0cf095635bee:/opt# codedoc build

# Building ...
# Fetching project configuration ...
# building ........ docs/md/index.md
# built:: ......... index.html
# building ........ docs/md/docs/cheat-sheet.md
# built:: ......... docs/cheat-sheet.html
# building ........ docs/md/docs/code-features.md
# built:: ......... docs/code-features.html
# building ........ docs/assets/codedoc-styles.css
# built:: ......... docs/assets/codedoc-styles.css
# building ........ docs/assets/codedoc-bundle.js
# Build Failed.

root@0cf095635bee:/home/test# 
@loreanvictor loreanvictor added the bug Something isn't working label Dec 22, 2020
@loreanvictor
Copy link
Contributor

Ok so there seems to be an issue with webpack over-consuming memory while building in production mode. I will check CODEDOC's webpack configuration to see if there is room for optimizing anything via configs, but in the meanwhile I would recommend building on local machine instead of inside a container, or increasing memory limits of the container. To verify this, you can simply run codedoc serve instead of codedoc build and check if its working.

@loreanvictor loreanvictor changed the title Build of new project fails Production build memory consumption Dec 22, 2020
@loreanvictor
Copy link
Contributor

So this is the webpack config that results in OOM:

{
  "resolve": {
    "extensions": [
      ".tsx",
      ".ts",
      ".js"
    ],
    "modules": [
      ".codedoc/node_modules"
    ]
  },
  "resolveLoader": {
    "modules": [
      "node_modules",
      ".codedoc/node_modules"
    ]
  },
  "entry": "/opt/docs/assets/codedoc-bundle.entry.js",
  "output": {
    "filename": "codedoc-bundle.js",
    "path": "/opt/docs/assets"
  },
  "module": {
    "rules": [
      {
        "test": {},
        "use": "ts-loader",
        "exclude": {}
      }
    ]
  }
}

The only work-around right now seems to be turning off type checking on ts-loader. Since this is limited to building in production mode in memory-limited environments, I can recommend one of the following:

  • Do not build inside a container with memory limits. You can safely serve inside a container, using a Dockerfile like this and a compose file like this, for example.
  • Increase memory limit of your container
  • If you, for some reason, have no other options but to build inside a memory-limited container, change your build config in .codedoc/build.ts so that it builds in development mode:
import { build } from '@codedoc/core';

import { config } from './config';
import { installTheme$ } from './content/theme';
import { content } from './content';


build(config, content, installTheme$, {
  mode: 'development',        // --> this line is added
  resolve: {
    modules: ['.codedoc/node_modules']
  },
  resolveLoader: {
    modules: ['.codedoc/node_modules']
  }
});

Note that this is really not recommended as it results in bundles that are not minified properly. Generally speaking though, you should not need to build manually except for deployment, where you typically would not have such strict memory limitations.

Closing this issue since it does not seem the webpack / ts-loader team intend to tend to this anytime soon (unfortunately).

@loreanvictor loreanvictor added the pending on external library this issue is pending on another issue/PR of an external library label Dec 22, 2020
@TysonMN
Copy link
Contributor

TysonMN commented Dec 22, 2020

there seems to be an issue with webpack over-consuming memory while building in production mode.

How did you figure that out? Did you follow the reproduction steps and reproduce the problem yourself?

As a minimal improvement, how about adding output to codedoc build that something (or specifically webpack) ran out of memory?

@loreanvictor
Copy link
Contributor

How did you figure that out? Did you follow the reproduction steps and reproduce the problem yourself?

Naturally, also testing with different webpack configurations.

As a minimal improvement, how about adding output to codedoc build that something (or specifically webpack) ran out of memory?

I'm not sure how feasible this is, as the node process itself basically runs out of memory and crashes (webpack is executed on the same node process).

@TysonMN
Copy link
Contributor

TysonMN commented Dec 22, 2020

My previous project at work had a memory issue. It was a .NET application (written in C#). When a request for memory is larger than the available memory, an OutOfMemoryException is thrown. I caught this exception and decided to force kill the application by calling Environment.Exit(-1) but not before logging that the application would be terminated due to lack of memory. Additionally, I can keep tabs on how things are going by subscribing to both AppDomain.CurrentDomain.UnhandledException and AppDomain.CurrentDomain.FirstChanceException and then logging if either occur.

Does any of this give you an idea for how you can give more feedback when webpack runs out of memory?

The simplest improvement would be to log before and after webpack runs. Then users would know that the issue is with webpack.

@loreanvictor
Copy link
Contributor

The simplest improvement would be to log before and after webpack runs. Then users would know that the issue is with webpack.

It does already:

# building ........ docs/assets/codedoc-bundle.js
# Build Failed.

And I'm not sure about @ntimo , but I do get more detailed error messages when following reproduction steps here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending on external library this issue is pending on another issue/PR of an external library
Projects
None yet
Development

No branches or pull requests

3 participants