'wasm code commit Allocation failed - process out of memory

I have a nodejs script which was working fine on nodejs 12. I got a new macbook air on which I installed nodejs LTS 14. The scripts was not working as intended so I have downgraded it to nodejs 12 LTS. Now I'm getting an error for process out of memory. I have also tried using --max-oud-size to increase the memory allocation.

export NODE_OPTIONS=--max_old_space_size=4096

It didn't work. Following is the stack trace for the error


<--- Last few GCs --->

[8193:0x150008000]       41 ms: Scavenge 2.9 (4.9) -> 2.7 (5.7) MB, 0.5 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure 
[8193:0x150008000]       54 ms: Scavenge 3.9 (5.9) -> 3.6 (8.6) MB, 0.3 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure 
[8193:0x150008000]       59 ms: Scavenge 5.2 (8.6) -> 3.9 (9.1) MB, 0.2 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure 


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x00010b1808d1 <JSObject>
    0: builtin exit frame: new constructor(aka Module)(this=0x000102ea1961 <Object map = 0x10b3ecbc9>,0x000102ea1811 <Uint8Array map = 0x102fc2b99>,0x000102ea1961 <Object map = 0x10b3ecbc9>)

    1: ConstructFrame [pc: 0x100ca8758]
    2: StubFrame [pc: 0x100d91204]
    3: /* anonymous */ [0x102ea10b1] [/Applications/XAMPP/xamppfiles/htdocs/web-dev/local-cron-jobs/node_modules/long/src/long.js:9...

FATAL ERROR: wasm code commit Allocation failed - process out of memory
 1: 0x1004db324 node::Abort() [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
 2: 0x1004db4a4 node::errors::TryCatchScope::~TryCatchScope() [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
 3: 0x1005fab78 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
 4: 0x1005fab0c v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
 5: 0x100b332bc v8::internal::wasm::WasmCodeAllocator::AllocateForCodeInRegion(v8::internal::wasm::NativeModule*, unsigned long, v8::base::AddressRegion) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
 6: 0x100b34198 v8::internal::wasm::NativeModule::CreateEmptyJumpTableInRegion(unsigned int, v8::base::AddressRegion) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
 7: 0x100b33660 v8::internal::wasm::NativeModule::AddCodeSpace(v8::base::AddressRegion) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
 8: 0x100b33fd4 v8::internal::wasm::NativeModule::NativeModule(v8::internal::wasm::WasmEngine*, v8::internal::wasm::WasmFeatures const&, bool, v8::internal::VirtualMemory, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>, std::__1::shared_ptr<v8::internal::Counters>, std::__1::shared_ptr<v8::internal::wasm::NativeModule>*) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
 9: 0x100b36214 v8::internal::wasm::WasmCodeManager::NewNativeModule(v8::internal::wasm::WasmEngine*, v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, unsigned long, bool, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
10: 0x100b3cb1c v8::internal::wasm::WasmEngine::NewNativeModule(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, unsigned long, bool, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
11: 0x100b3ca64 v8::internal::wasm::WasmEngine::NewNativeModule(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
12: 0x100b14578 v8::internal::wasm::CompileToNativeModule(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, v8::internal::wasm::ErrorThrower*, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>, v8::internal::wasm::ModuleWireBytes const&, v8::internal::Handle<v8::internal::FixedArray>*) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
13: 0x100b3a710 v8::internal::wasm::WasmEngine::SyncCompile(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, v8::internal::wasm::ErrorThrower*, v8::internal::wasm::ModuleWireBytes const&) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
14: 0x100b5bc98 v8::(anonymous namespace)::WebAssemblyModule(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
15: 0x10065f150 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
16: 0x10065e4b8 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<true>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
17: 0x10065dfb4 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
18: 0x100d2b0cc Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
19: 0x100ca8758 Builtins_JSBuiltinsConstructStub [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
20: 0x100d91204 Builtins_ConstructHandler [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
21: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
22: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
23: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
24: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
25: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
26: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
27: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
28: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
29: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
30: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
31: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
32: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
33: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
34: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
35: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
36: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
37: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
38: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
39: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
40: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
41: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
42: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
43: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
44: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
45: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
46: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
47: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
48: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
49: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
50: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
51: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
52: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
53: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
54: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
55: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
56: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
57: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
58: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
59: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
60: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
61: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
62: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
63: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
64: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
65: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
66: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
67: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
68: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
69: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
70: 0x100caa5a8 Builtins_JSEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
71: 0x100caa24c Builtins_JSEntry [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
72: 0x150008000 ```

Any help appreciated. Thanks.


Solution 1:[1]

This issue has been fixed in Node 15.3.0.

I updated mine and it worked fine for me.

Solution 2:[2]

Currently, node on M1 macOS doesn't work well except node@15. If you using node@12 built on arm64 architecture, it may be crashed on some scripts such as https://github.com/dcodeIO/long.js.git

You can check it if you run test cases in long.js repository.

If you would like to know on which your node is built, please follow this:

$ node

Welcome to Node.js v12.21.0.
Type ".help" for more information.
>
> process.arch
'arm64'

The above example means the node binary is built for arm64 architecture (Apple Silicon M1 chip). If node is run on rosetta2, it will display 'x64'.

I have tested some test cases in long.js and node.js source repository.

  • Node@15 for arm64: no problem
  • Node@12 for arm64: some errors in long.js and node.js test cases
  • Node@12 for x64: no problem

As I know, node@12 for arm64 works well for some scripts, but some scripts has been crashed such as long.js.

Edit

On June 21th, 2021, node@14 on Homebrew has passed long.js test cases for arm64. (v14.17.1) Of course, node@16 also supports it.

But, node@12 still has errors on them. (v12.22.1)

Solution 3:[3]

Can't upgrade node & need a quick two minute solution?

For anyone who is on an M1 computer and suffering from this issue and cannot upgrade their node version for whatever the reason may be, there is still a quick & easy workaround:

  1. Go to your Application/Utilities folder where your Terminal resides. (An easy way to find this is right click on your terminal icon and click "Open in finder".) Here is a screenshot: Picture depicting the Application/Utilities directory and right clicking on the "Terminal" application and highlighting the "Duplicate" option
  2. Right click on terminal and click "Duplicate" and then rename the new terminal to something like "Rosetta-Terminal". (Bottom left in the screenshot above.)
  3. Right click on Rosetta-Terminal --> "Get Info" --> select "Open using Rosetta". Image of duplicated terminal that is showing the clicking of "Open using Rosetta" option
  4. Now open the Rosetta-Terminal and using nvm type nvm uninstall YOUR.VERSION.HERE. (Note: it may say that it's unable to install it since you're currently using it, in which case just install any other version temporarily and use that.) If you do not have nvm then you can install it here or by running: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash.
  5. nvm install YOUR.VERSION.HERE

Boom, now your node is installed under Rosetta and it should work fine without the need to upgrade your node version.

Rosetta is Apple's way of allowing apps built for the Intel chip to work with Apple Silicon.

It's not always easy to upgrade your node version as other answers seem to suggest. For example perhaps you have other dependencies that require a specific node version and upgrading those dependencies would require a significant lift and shift of your app - luckily for those scenarios we have Rosetta.

Solution 4:[4]

This code block was able to get me past this frustrating error:

$ nvm uninstall 14
$ arch -x86_64 zsh 
$ nvm install 14
$ nvm alias default 14

Consider replacing 14 above with whichever node version you are attempting to run under.

After installing, you can run node followed process.arch to confirm that node is running in x64 mode:

$ node
> process.arch
'x64'

You will then need to delete your node modules from your project folder (rm -rf node_modules) and run npm i again.

Solution 5:[5]

Using NVM installed from Github on M1.

Was running v14.x

nvm install 15.3

Compile took around 10 mins.

Works now.

Solution 6:[6]

I was getting this error with the node version v14.

To resolve this, I installed NVM(node version manager). With the help of this, I was able to install the latest version of the node i.e. v15. After installing the latest version, I didn't get any errors. Also, with node version manager(NVM), one can easily change versions of node ,if needed for a certain project. That can be really helpful at times.

Good Luck !

Solution 7:[7]

I was able to fix the crash with v14.16.0 by applying the changes of this pull request as a patch when compiling node.

To simplify this I've created a gist with the patch.

With node-build / nodenv

Installation commands:

curl -LO https://gist.githubusercontent.com/koenpunt/812953470f26b100845e2b37e1288067/raw/667daea235ac99236adb2dfa1499401358d004dd/node-14.16.0.patch
node-build -p 14.16.0 $(nodenv root)/versions/14.16.0 < node-14.16.0.patch

When not using nodenv, you should replace $(nodenv root)/versions/14.16.0 with the path where you want to install node.

Without node-build

When not using node-build you should be able to apply the patch to the source yourself using git-apply:

git apply node-14.16.0.patch

Or using the patch command:

patch -p1 < node-14.16.0.patch

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeongmin Woo
Solution 2
Solution 3
Solution 4 Sators
Solution 5 maxshuty
Solution 6 Kirandeep Kaur
Solution 7