Skip to content

"npx webpack" fails with "RangeError: WebAssembly.Instance(): Out of memory: wasm memory" #15584

Closed

Description

@d0sboots

Bug report

What is the current behavior?
Attempting to run webpack leads to the following error:

$ npm view webpack version
5.70.0
$ npx webpack
[webpack-cli] RangeError: WebAssembly.Instance(): Out of memory: wasm memory
    at create (/home/davedude/public_html/ConjunctionJunction/node_modules/webpack/lib/util/hash/wasm-hash.js:154:4)
    at module.exports (/home/davedude/public_html/ConjunctionJunction/node_modules/webpack/lib/util/createHash.js:160:27)
    at /home/davedude/public_html/ConjunctionJunction/node_modules/webpack/lib/DefinePlugin.js:289:22
    at _next31 (eval at create (/home/davedude/public_html/ConjunctionJunction/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:40:1)
    at _next9 (eval at create (/home/davedude/public_html/ConjunctionJunction/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:95:1)
    at Hook.eval [as call] (eval at create (/home/davedude/public_html/ConjunctionJunction/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:117:1)
    at Hook.CALL_DELEGATE [as _call] (/home/davedude/public_html/ConjunctionJunction/node_modules/tapable/lib/Hook.js:14:14)
    at Compiler.newCompilation (/home/davedude/public_html/ConjunctionJunction/node_modules/webpack/lib/Compiler.js:1109:26)
    at /home/davedude/public_html/ConjunctionJunction/node_modules/webpack/lib/Compiler.js:1153:29
    at Hook.eval [as callAsync] (eval at create (/home/davedude/public_html/ConjunctionJunction/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:4:1)

If the current behavior is a bug, please provide the steps to reproduce.

The issue first appeared in release 5.61:

$ npm install [email protected] --save-dev --fund=false --audit=false

changed 1 package in 824ms
$ npx webpack
...same issue...

$ npm install [email protected] --save-dev --fund=false --audit=false

changed 1 package in 891ms
$ npx webpack
assets by status 0 bytes [cached] 1 asset

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value.
Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/

ERROR in main
Module not found: Error: Can't resolve './src' in '/home/davedude/public_html/ConjunctionJunction'
resolve './src' in '/home/davedude/public_html/ConjunctionJunction'
  using description file: /home/davedude/public_html/ConjunctionJunction/package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    using description file: /home/davedude/public_html/ConjunctionJunction/package.json (relative path: ./src)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /home/davedude/public_html/ConjunctionJunction/src doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        /home/davedude/public_html/ConjunctionJunction/src.js doesn't exist
      .json
        Field 'browser' doesn't contain a valid alias configuration
        /home/davedude/public_html/ConjunctionJunction/src.json doesn't exist
      .wasm
        Field 'browser' doesn't contain a valid alias configuration
        /home/davedude/public_html/ConjunctionJunction/src.wasm doesn't exist
      as directory
        /home/davedude/public_html/ConjunctionJunction/src doesn't exist

webpack 5.60.0 compiled with 1 error and 1 warning in 148 ms

The repro environment is an empty package, no src/ directory. (It dies before that matters.)

The issue appears to be strongly related to this blog post: https://blog.stackblitz.com/posts/debugging-v8-webassembly/, which indicates that a fix in v8 was needed (or coding differently, to create fewer Instances).

I first encountered this issue with Node v12.22.10 (which is listed as supported), which has a v8 version well before the fix landed.

I also tried Node v14.19.1, which is the latest version available from Debian. Same issue.

The commit in Node that fixes the issue in V8 is here: nodejs/node@3e9939e

If I'm reading it right, that means this code only works with Node v17.2.0 or later. Or (more likely) there's an additional repro condition I don't know about.

What is the expected behavior?

Doesn't crash.

Other relevant information:
webpack version: 5.61+
Node.js version: v12.22.10, v14.19.1
Operating System: Debian/testing
Additional tools:

Activity

  1. vankop commented on Mar 25, 2022

    @vankop
    Contributor

    Did you try with Node.js v16 ?

  2. alexander-akait commented on Mar 25, 2022

    @alexander-akait
    Member

    @d0sboots Can you provide more information, do you using snap/official repository or custom setup/build for Node.js?

  3. d0sboots commented on Mar 25, 2022

    @d0sboots
    Author

    I was using the system-global version(s) of Node that come from Debian. 14.19.1 is the latest version on the unstable tree. I'll spend some time today trying different Node versions and report back.

  4. d0sboots commented on Mar 25, 2022

    @d0sboots
    Author

    So, here's how this reproduces on my machine. Create an empty directory, install webpack and (optionally) a version of Node:

    $ mkdir newdir; cd newdir
    $ npm i node@16 webpack webpack-cli --fund=false --audit=false
    
    added 122 packages in 10s
    $ npm exec -- node -v
    v16.14.0
    

    Trying to run webpack results in the error:

    $ npm exec -- webpack
    [webpack-cli] RangeError: WebAssembly.Instance(): Out of memory: wasm memory
        at create (/home/davedude/newdir/node_modules/webpack/lib/util/hash/wasm-hash.js:154:4)
        at module.exports (/home/davedude/newdir/node_modules/webpack/lib/util/createHash.js:160:27)
        at /home/davedude/newdir/node_modules/webpack/lib/DefinePlugin.js:289:22
        at _next31 (eval at create (/home/davedude/newdir/node_modules/tapable/lib/HookCodeFactory.js:1:1), <anonymous>:42:1)
        at _next9 (eval at create (/home/davedude/newdir/node_modules/tapable/lib/HookCodeFactory.js:1:1), <anonymous>:97:1)
        at Hook.eval [as call] (eval at create (/home/davedude/newdir/node_modules/tapable/lib/HookCodeFactory.js:1:1), <anonymous>:119:1)
        at Hook.CALL_DELEGATE [as _call] (/home/davedude/newdir/node_modules/tapable/lib/Hook.js:14:14)
        at Compiler.newCompilation (/home/davedude/newdir/node_modules/webpack/lib/Compiler.js:1109:26)
        at /home/davedude/newdir/node_modules/webpack/lib/Compiler.js:1153:29
        at Hook.eval [as callAsync] (eval at create (/home/davedude/newdir/node_modules/tapable/lib/HookCodeFactory.js:1:1), <anonymous>:6:1)
    

    I was wrong in my guess about the instances fix in V8; using a Node version past 17.2.0 has no effect:

    $ npm i node@17 --fund=false --audit=false
    
    changed 1 package in 5s
    
    $ npm exec -- node -v
    v17.7.1
    $ npm exec -- webpack
    [webpack-cli] RangeError: WebAssembly.Instance(): Out of memory: wasm memory
        at create (/home/davedude/newdir/node_modules/webpack/lib/util/hash/wasm-hash.js:154:4)
        at module.exports (/home/davedude/newdir/node_modules/webpack/lib/util/createHash.js:160:27)
        at /home/davedude/newdir/node_modules/webpack/lib/DefinePlugin.js:289:22
        at _next31 (eval at create (/home/davedude/newdir/node_modules/tapable/lib/HookCodeFactory.js:1:1), <anonymous>:42:1)
        at _next9 (eval at create (/home/davedude/newdir/node_modules/tapable/lib/HookCodeFactory.js:1:1), <anonymous>:97:1)
        at Hook.eval [as call] (eval at create (/home/davedude/newdir/node_modules/tapable/lib/HookCodeFactory.js:1:1), <anonymous>:119:1)
        at Hook.CALL_DELEGATE [as _call] (/home/davedude/newdir/node_modules/tapable/lib/Hook.js:14:14)
        at Compiler.newCompilation (/home/davedude/newdir/node_modules/webpack/lib/Compiler.js:1109:26)
        at /home/davedude/newdir/node_modules/webpack/lib/Compiler.js:1153:29
        at Hook.eval [as callAsync] (eval at create (/home/davedude/newdir/node_modules/tapable/lib/HookCodeFactory.js:1:1), <anonymous>:6:1)
    

    But it's definitely caused by a change in Webpack; syncing before the m4-based wasm hashing was introduced in 5.61 fixes it, always.

    $ npm i [email protected] --fund=false --audit=false
    
    added 1 package, and changed 1 package in 877ms
    $ npm exec -- webpack
    [webpack-cli] Error: error:0308010C:digital envelope routines::unsupported
        at new Hash (node:internal/crypto/hash:67:19)
        at Object.createHash (node:crypto:135:10)
        at BulkUpdateDecorator.hashFactory (/home/davedude/newdir/node_modules/webpack/lib/util/createHash.js:155:18)
        at BulkUpdateDecorator.digest (/home/davedude/newdir/node_modules/webpack/lib/util/createHash.js:80:21)
        at /home/davedude/newdir/node_modules/webpack/lib/DefinePlugin.js:595:38
        at _next30 (eval at create (/home/davedude/newdir/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:42:1)
        at _next8 (eval at create (/home/davedude/newdir/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:97:1)
        at Hook.eval [as call] (eval at create (/home/davedude/newdir/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:117:1)
        at Hook.CALL_DELEGATE [as _call] (/home/davedude/newdir/node_modules/tapable/lib/Hook.js:14:14)
        at Compiler.newCompilation (/home/davedude/newdir/node_modules/webpack/lib/Compiler.js:1053:26) {
      opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
      library: 'digital envelope routines',
      reason: 'unsupported',
      code: 'ERR_OSSL_EVP_UNSUPPORTED'
    }
    

    (The above is the error that the m4-based hashes were added to address, in Node 17. It works fine in earlier Nodes, you get a sensible error about lacking a src/ dir.)

  5. alexander-akait commented on Mar 28, 2022

    @alexander-akait
    Member

    What is npm version?

  6. d0sboots commented on Mar 29, 2022

    @d0sboots
    Author
    $ npm --version
    8.5.5
    
  7. alexander-akait commented on Mar 29, 2022

    @alexander-akait
    Member

    I still can't reproduce, as you can see there is no 👍, maybe related to your env (broken node installation or due debian/testing)

  8. d0sboots commented on Apr 20, 2022

    @d0sboots
    Author

    Got around to digging further on this. I suspected this was something specific to my env as well.

    $ node
    Welcome to Node.js v14.19.1.
    Type ".help" for more information.
    > foo = new WebAssembly.Memory({ initial:1 })
    Uncaught RangeError: WebAssembly.Memory(): could not allocate memory
    

    This shows that WASM is basically totally inoperable; trying to allocate anything at all is failing. I'll update again if/when I get to the bottom of this, so that if anyone else runs into the same issue they'll know how to fix it.

  9. d0sboots commented on Apr 21, 2022

    @d0sboots
    Author

    I found the issue.

    V8 uses 10GB memory allocations in WASM to implement guard regions. Most of this memory is never committed (actually given pages by the VM system), but the virtual address space is still consumed.

    I had a 5GB ulimit set, for safety. Once that was removed, everything worked fine.

  10. Alexsab commented on Jun 3, 2022

    @Alexsab

    @d0sboots how did you do that? I catch the same error

  11. etayakee commented on Jun 3, 2022

    @etayakee

    @d0sboots how did you do that? I catch the same error

  12. d0sboots commented on Jun 4, 2022

    @d0sboots
    Author

    If you put in ulimit -a, you should see something like this:

    -t: cpu time (seconds)              unlimited
    -f: file size (blocks)              unlimited
    -d: data seg size (kbytes)          unlimited
    -s: stack size (kbytes)             8192
    -c: core file size (blocks)         0
    -m: resident set size (kbytes)      unlimited
    -u: processes                       31275
    -n: file descriptors                1024
    -l: locked-in-memory size (kbytes)  1004968
    -v: address space (kbytes)          unlimited
    -x: file locks                      unlimited
    -i: pending signals                 31275
    -q: bytes in POSIX msg queues       819200
    -e: max nice                        0
    -r: max rt priority                 0
    -N 15: rt cpu time (microseconds)   unlimited
    

    If the values for -d (data seg size), -m (resident set size), or especially -v (address space) are not "unlimited", that means you have a ulimit set and you're probably having the same issue I did.

    As to how to fix it, it'll be set in the shell files... somewhere. Maybe your .profile, .bashrc, etc. Maybe the system version of the same. It depends on what shell you're running, what OS/distribution, etc.

  13. added a commit that references this issue on Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions