aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

FETAL ERROR: Reached heap limit Allocation failed - Javascript heap out of memory #10830

Closed ysabri closed 1 year ago

ysabri commented 1 year ago

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

``` # Put output below this line System: OS: Windows 10 10.0.18363 CPU: (16) x64 AMD Ryzen 7 PRO 4750U with Radeon Graphics Memory: 12.29 GB / 31.23 GB Binaries: Node: 16.13.1 - C:\Program Files\nodejs\node.EXE npm: 8.1.1 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Spartan (44.18362.1533.0) Internet Explorer: 11.0.18362.1 npmPackages: @asseinfo/react-kanban: ^2.2.0 => 2.2.0 @aws-amplify/ui-react: ^4.3.1 => 4.3.1 @aws-amplify/ui-react-internal: undefined () @date-io/date-fns: ^1.3.13 => 1.3.13 @date-io/dayjs: ^1.3.13 => 1.3.13 @material-ui/core: ^4.12.2 => 4.12.3 @material-ui/icons: ^4.11.1 => 4.11.2 @material-ui/lab: ^4.0.0-alpha.58 => 4.0.0-alpha.60 @material-ui/pickers: ^3.2.10 => 3.3.10 @paypal/react-paypal-js: ^7.8.1 => 7.8.1 @testing-library/react: ^12.1.0 => 12.1.2 @types/jest: ^27.0.1 => 27.0.3 @types/lodash: ^4.14.176 => 4.14.178 @types/material-ui-phone-number: ^2.2.1 => 2.2.1 @types/mixpanel-browser: ^2.38.0 => 2.38.0 @types/node: ^17.0.4 => 17.0.4 (14.18.13) @types/react: ^17.0.37 => 17.0.38 (16.14.21) @types/react-dom: ^17.0.11 => 17.0.11 @types/react-image-gallery: ^1.2.0 => 1.2.0 @types/react-router-dom: ^5.3.2 => 5.3.2 @types/react-test-renderer: ^17.0.1 => 17.0.1 @types/ua-parser-js: ^0.7.36 => 0.7.36 @types/uuid: ^8.3.4 => 8.3.4 @use-it/interval: ^1.0.0 => 1.0.0 aws-amplify: ^5.0.8 => 5.0.8 aws-sdk: ^2.1248.0 => 2.1284.0 bottleneck: ^2.19.5 => 2.19.5 browser-image-compression: ^2.0.0 => 2.0.0 cross-env: ^7.0.3 => 7.0.3 cypress: ^9.5.4 => 9.5.4 d3-ease: ^3.0.1 => 3.0.1 date-fns: ^2.16.1 => 2.27.0 dayjs: ^1.11.1 => 1.11.1 env-cmd: ^10.1.0 => 10.1.0 http-server: ^14.1.0 => 14.1.0 immutability-helper: ^3.1.1 => 3.1.1 jest-fetch-mock: ^3.0.3 => 3.0.3 jszip: ^3.10.1 => 3.10.1 libphonenumber-js: ^1.9.41 => 1.9.44 libphonenumber-js-core: 1.0.0 libphonenumber-js-max: 1.0.0 libphonenumber-js-min: 1.0.0 libphonenumber-js-mobile: 1.0.0 linkify-react: ^4.0.1 => 4.0.1 linkifyjs: ^4.0.1 => 4.0.1 material-ui-phone-number: ^2.2.6 => 2.2.6 mixpanel-browser: ^2.45.0 => 2.45.0 moment: ^2.29.1 => 2.29.4 node-polyfill-webpack-plugin: ^2.0.1 => 2.0.1 puppeteer: ^13.5.1 => 13.5.1 rdndmb-html5-to-touch: ^7.1.3 => 7.1.3 react: ^17.0.2 => 17.0.2 (16.14.0) react-circular-progressbar: ^2.0.4 => 2.0.4 react-cookie: ^4.1.1 => 4.1.1 react-cookie-consent: ^7.2.1 => 7.2.1 react-countup: ^6.1.1 => 6.1.1 react-dnd: ^15.1.2 => 15.1.2 react-dnd-multi-backend: ^7.1.3 => 7.1.3 react-dom: ^17.0.2 => 17.0.2 (16.14.0) react-error-boundary: ^3.1.4 => 3.1.4 react-ga4: ^1.4.1 => 1.4.1 react-helmet: ^6.1.0 => 6.1.0 react-hyphen: ^1.4.0 => 1.4.0 react-idle-timer: ^5.4.2 => 5.4.2 react-image-gallery: ^1.2.11 => 1.2.11 react-material-ui-carousel: ^2.3.8 => 2.3.8 react-move: ^6.5.0 => 6.5.0 react-router-dom: ^6.2.1 => 6.2.1 react-scripts: ^5.0.0 => 5.0.1 react-test-renderer: ^17.0.2 => 17.0.2 react-toastify: ^8.2.0 => 8.2.0 react-typist: 2.0.5 => 2.0.5 react-visibility-sensor: ^5.1.1 => 5.1.1 react-zoom-pan-pinch: ^2.1.3 => 2.1.3 sass: ^1.49.7 => 1.49.7 shave: ^2.5.10 => 2.5.10 source-map-explorer: ^2.5.2 => 2.5.2 typescript: ^4.9.3 => 4.9.3 use-debounce: ^7.0.0 => 7.0.1 uuid: ^8.3.2 => 8.3.2 (3.4.0, 3.3.2, 8.0.0) validate.js: ^0.13.1 => 0.13.1 web-vitals: ^0.2.4 => 0.2.4 workbox-background-sync: ^6.5.3 => 6.5.3 (6.4.2) workbox-broadcast-update: ^6.5.3 => 6.5.3 (6.4.2) workbox-cacheable-response: ^6.5.3 => 6.5.3 (6.4.2) workbox-core: ^6.5.3 => 6.5.3 (6.4.2) workbox-expiration: ^6.5.3 => 6.5.3 (6.4.2) workbox-google-analytics: ^6.5.3 => 6.5.3 (6.4.2) workbox-navigation-preload: ^6.5.3 => 6.5.3 (6.4.2) workbox-precaching: ^6.5.3 => 6.5.3 (6.4.2) workbox-range-requests: ^6.5.3 => 6.5.3 (6.4.2) workbox-routing: ^6.5.3 => 6.5.3 (6.4.2) workbox-strategies: ^6.5.3 => 6.5.3 (6.4.2) workbox-streams: ^6.5.3 => 6.5.3 (6.4.2) npmGlobalPackages: @aws-amplify/cli: 8.0.2 cheerio: 1.0.0-rc.10 create-react-app: 5.0.0 create-react: 0.0.0 depcheck: 1.4.2 esm: 3.2.25 ndb: 1.1.5 npm: 8.1.1 presite: 2.1.2 puppeteer: 13.5.1 react-scripts: 5.0.0 serve: 13.0.2 ts-node: 10.7.0 typings: 2.1.1 ```

Describe the bug

So I'm upgrading from an old version (4.3.11) of aws-amplify to 5.0.8.

After doing the upgrade my build started running out of memory. I increased the max-old-space-size to 8192, that worked but the build at first would take almost all the space then go down to normal size (below 3GB).

Expected behavior

The build shouldn't need that much memory.

Reproduction steps

I looked at how I was importing amplify, this was my old code that caused the issue:

import Amplify from '@aws-amplify/core';
...
Amplify.configure(amplifyConfig)

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

Changing my amplify import to the one the documentation has:

import {Amplify} from 'aws-amplify';

Solves the issue.

I just wanted to point this out as I don't know why an import of a class that is exported by the library would cause such behavior.

nadetastic commented 1 year ago

Hi @ysabri thank you for opening this issue. Amplify as a default export is currently deprecated and it's recommended to import as named export.

ysabri commented 1 year ago

Hi @nadetastic, thanks for getting back to me on this so quickly. I haven't done any source map analysis yet but I'm assuming importing like this will get split out appropriately after tree shaking so I'm not importing the entirety of the library.

nadetastic commented 1 year ago

@ysabri that is correct, tree shaking will be done and remove any packages you aren't using. If you don't have any additional questions, I'll close this issue out shortly 🙂