rxaviers / cldr-data-npm

Npm module for Unicode CLDR JSON data
MIT License
42 stars 27 forks source link

JavaScript heap out of memory #55

Closed xehpuk closed 5 months ago

xehpuk commented 6 years ago

I have a file with the line const cldr = require('cldr-data'). When importing the file, Node eats more and more RAM until…

$ webpack-dev-server --config webpack.config.js -d --watch

<--- Last few GCs --->

[15088:0000015D8C7B99E0]   157944 ms: Mark-sweep 1245.7 (1583.9) -> 1245.5 (1585.4) MB, 462.8 / 0.0 ms  allocation failure GC in old space requested
[15088:0000015D8C7B99E0]   158428 ms: Mark-sweep 1245.5 (1585.4) -> 1244.5 (1536.9) MB, 483.7 / 0.0 ms  last resort GC in old space requested
[15088:0000015D8C7B99E0]   158913 ms: Mark-sweep 1244.5 (1536.9) -> 1244.5 (1521.9) MB, 484.6 / 0.0 ms  last resort GC in old space requested

<--- JS stacktrace --->

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

Security context: 000003FD2EBA5529 <JSObject>
    0: builtin exit frame: stringify(this=000003FD2EB88D59 <Object map = 0000037CAA182BA1>,000000EAF32822D1 <undefined>,000000EAF32822D1 <undefined>,000001DE350DC281 <Very long string[469998]>)

    1: arguments adaptor frame: 1->3
    2: /* anonymous */ [...\node_modules\webpack\lib\EvalSourceMapDevToolModuleTemplatePlugin.js:66] [bytecode=0000030ED3173019 ...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::DecodeWrite
 2: node_module_register
 3: v8::internal::FatalProcessOutOfMemory
 4: v8::internal::FatalProcessOutOfMemory
 5: v8::internal::Factory::NewRawTwoByteString
 6: v8::internal::Smi::SmiPrint
 7: v8::internal::StackGuard::HandleInterrupts
 8: v8::internal::wasm::LocalDeclEncoder::Size
 9: v8::internal::wasm::LocalDeclEncoder::Size
10: v8_inspector::protocol::Debugger::API::SearchMatch::fromJSONString
11: v8_inspector::protocol::Debugger::API::SearchMatch::fromJSONString
12: 0000012CCAD86B21
error An unexpected error occurred: "Command failed.
Exit code: 134

What's wrong here?

rxaviers commented 6 years ago

Please, can you share in a gist a minimum way to reproducible the issue you see?

Usnul commented 6 years ago

related https://github.com/angular/angular-cli/issues/5618

rxaviers commented 6 years ago

require('cldr-data') can't be used with webpack because when it sees dynamic imports, webpack simply includes everything.

It works including things explicitly such as import enNumbers from "cldr-data/main/en/numbers.json" (tedious). A better alternative is using plugins such as globalize webpack plugin (if using globalize).

We need to update README.md to reflect this. Do you want to help?

ConorSheehan1 commented 5 years ago

require('cldr-data') can't be used with webpack because when it sees dynamic imports, webpack simply includes everything.

It works including things explicitly such as import enNumbers from "cldr-data/main/en/numbers.json" (tedious). A better alternative is using plugins such as globalize webpack plugin (if using globalize).

We need to update README.md to reflect this. Do you want to help?

Using the import syntax stops the heap overflow, but it still doesn't compile for me.

ERROR in ./node_modules/globalize/dist/globalize/number.js
Module not found: Error: Can't resolve 'cldr/supplemental' in '/Users/me/Workspace/my_app/node_modules/globalize/dist/globalize'
 @ ./node_modules/globalize/dist/globalize/number.js 22:2-27:14
 @ ./node_modules/globalize/dist/node-main.js
 @ ./client/js/filters/compactNumber.js
 @ ./client/js/filters \.js$
 @ ./client/app.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:9000 webpack/hot/dev-server babel-polyfill ./client/app.js

I'm trying to use Globalize.numberFormatter. Here's what I'm trying to load:

let Globalize = require('globalize');
// minimum required cldr-data to use Globalize.numberFormatter({ compact: 'short', maximumFractionDigits: 0 })
// generated by http://johnnyreilly.github.io/globalize-so-what-cha-want/#/?currency=false&date=false&message=false&number=true&plural=false&relativeTime=false&unit=false
import enNumbers from 'cldr-data/main/en/numbers.json';
import likelySubtags from 'cldr-data/supplemental/likelySubtags.json';
import numbers from 'cldr-data/supplemental/numberingSystems.json';
Globalize.load(enNumbers);
Globalize.load(likelySubtags);
Globalize.load(numbers);
heyakyra commented 2 years ago

A better alternative is using plugins such as globalize webpack plugin (if using globalize)

This seems unmaintained. Trying to install causes conflicts for me because it's webpack dependency is too old

MehmetYararVX commented 5 months ago

Similar error caused by the inflight package: https://github.com/isaacs/inflight/issues/5