相关疑难解决方法(0)

`react-scripts build' 使用 1+ GB 的内存

我有一个相对简单的 React 15 网站。它只有几个不同的页面,主要是文字和一些图片。但是,当我用于react-scripts build构建用于生产部署的项目时,我发现节点进程最高使用了大约1.25 GB的 RAM。在我的工作站上构建时这不是问题,但在我的生产服务器上是一个问题,我目前只有1 GB的可用 RAM。大多数情况下,服务器会因为内存不足而终止我的构建。

所以看起来我的选择是花更多的钱升级到服务器上的2GB内存,或者找到一些方法来减少内存使用。我想避免支付更多费用,因为通常我不会使用超过200 MB的 RAM 来运行我的应用程序,而且它只是构建使用大量 RAM 的应用程序。

我似乎有些人建议--max-old-space-size=在构建中添加一个标志,但这似乎没有任何作用。也就是说,我已经在我的 package.json 中尝试过这个:

"build": "react-scripts --max-old-space-size=512 build"
Run Code Online (Sandbox Code Playgroud)

但它仍然使用了1+ GB的 RAM。我通过 开始构建npm run build,并将--max-old-space-size标志添加到该npm命令似乎没有任何作用。

我能做些什么来防止react-scripts构建过程使用这么多内存?

build reactjs react-scripts

23
推荐指数
1
解决办法
4532
查看次数

如何使用 Next.js 为 Javascript 堆分配更多内存

我们的 Next.js 应用程序的开发环境存在问题。

问题

我们的 Javascript 堆不断耗尽内存。以下是具体的错误日志:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 0x10003ae75 node::Abort() [/usr/local/bin/node]
 2: 0x10003b07f node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 3: 0x1001a7ae5 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 4: 0x100572ef2 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
 5: 0x10057c3f4 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
 6: 0x10054e1e4 v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
 7: 0x10067fd99 v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [/usr/local/bin/node]
 8: 0x1001c587d v8::String::Utf8Length() const [/usr/local/bin/node]
 9: 0x10004e7b6 node::Buffer::(anonymous namespace)::ByteLengthUtf8(v8::FunctionCallbackInfo<v8::Value> const&) [/usr/local/bin/node]
10: 0x2b9f4f0078a1 
Abort trap: 6
Run Code Online (Sandbox Code Playgroud)

具体做法是:我有,她注意到的问题 有些 相似的,但是当我们尝试运行这样一个节点的命令: …

javascript node.js reactjs next.js

9
推荐指数
1
解决办法
5067
查看次数

create-react-app max_old_space_size 不起作用

在使用 create-react-app 构建或运行我的项目时遇到问题。它抛出js堆内存不足错误。

> yarn build
yarn run v1.6.0
$ react-scripts build
Creating an optimized production build...

<--- Last few GCs --->

[8792:0000021D06B28B70]  1492086 ms: Mark-sweep 1401.7 (1716.2) -> 1401.7 (1716.2) MB, 1474.4 / 0.0 ms  allocation failure GC in old space requested
[8792:0000021D06B28B70]  1493542 ms: Mark-sweep 1401.7 (1716.2) -> 1401.5 (1658.7) MB, 1455.7 / 0.0 ms  last resort GC in old space requested
[8792:0000021D06B28B70]  1494983 ms: Mark-sweep 1401.5 (1658.7) -> 1401.5 (1636.7) MB, 1439.7 / 0.0 ms  last resort …
Run Code Online (Sandbox Code Playgroud)

javascript memory size heap-memory create-react-app

7
推荐指数
1
解决办法
4555
查看次数

如何解决“致命错误:堆限制附近的无效标记压缩无效分配失败-JavaScript堆内存不足”错误

我正在尝试将reactjs应用程序部署到heroku。编译资产时,构建失败并产生以下错误:

-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.5.1
-----> Installing dependencies using bundler 1.15.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
       Fetching gem metadata from https://rubygems.org/............
       Fetching version metadata from https://rubygems.org/..
       Fetching dependency metadata from https://rubygems.org/.
       Using rake 12.3.1 …
Run Code Online (Sandbox Code Playgroud)

node.js reactjs webpack

6
推荐指数
6
解决办法
6474
查看次数

在 ReactJS 中构建纱线,分配失败 - JavaScript 堆内存不足

在本地环境中我没有问题,但是使用此脚本在 jenkins 上运行生产环境确实可以:

yarn install --production
yarn build
Run Code Online (Sandbox Code Playgroud)

构建大约需要 5 分钟,最后,jenkins 退出并显示此控制台输出错误:

+ yarn install --production
yarn install v1.9.4
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > bootstrap@4.3.1" has unmet peer dependency "jquery@1.9.1 - 3".
warning " > bootstrap@4.3.1" has unmet peer dependency "popper.js@^1.14.7".
warning " > google-maps-react@1.1.11" has incorrect peer dependency …
Run Code Online (Sandbox Code Playgroud)

node-modules reactjs yarnpkg yarn-lock.json

4
推荐指数
4
解决办法
2万
查看次数