swc icon indicating copy to clipboard operation
swc copied to clipboard

Huge memory usage when compiling a particular JS library

Open sryze opened this issue 3 years ago • 2 comments

Describe the bug

When I compile code that imports react-ziggeo with webpack or spack, it makes the Node process run out of memory. This happens only on Windows. When I do the same inside WSL or on Linux for example, compilation finishes successfully.

Example:

$ npx webpack
memory allocation of 23124316044 bytes failed
/c/Program Files/nodejs/npx: line 35:  3789 Segmentation fault      "$NODE_EXE" "$NPX_CLI_JS" "$@"

Example screenshot of RAM usage from Process Explorer:

image

Input code

import ReactZiggeo from 'react-ziggeo';
export default function MyComponent() {
    return <ReactZiggeo/>
}

See the attached archive (test.zip) for the full code (package.json, etc).

Config

.swcrc:

{
    "jsc": {
        "parser": {
            "syntax": "ecmascript",
            "jsx": true,
            "classProperty": true,
            "dynamicImport": false
        }
    },
    "env": {
        "mode": "entry",
        "coreJs": 3
    }
}

spack.config.js:

module.exports = {
    entry: {
      web: __dirname + "/test.js",
    },
    output: {
      path: __dirname + "/dist",
    },
  };

Playground link

No response

Expected behavior

Expected to compile successfully and produce a bundle

Actual behavior

Fails to allocate memory and exits

Version

1.2.194, 1.2.196

Additional context

test.zip

sryze avatar May 29 '22 14:05 sryze

the problem is react-ziggeo includes a minified ziggeo-client-sdk which has about 2328342 characters in one line and 2866 with keyword which cause swc raised same number of WithInStrict error. After I change it to only emit part of error it works fine. relative issues: https://github.com/Ziggeo/ziggeo-client-sdk/issues/60 https://github.com/Ziggeo/react-ziggeo/pull/39#issuecomment-1104084682


btw, can we only print the code near the error happen? print the whole 2328342 characters in one line in console, looks really crazy.

RiESAEX avatar Aug 05 '22 04:08 RiESAEX

Yeah I think so, thank you for investigating!

kdy1 avatar Aug 05 '22 04:08 kdy1