wallabyjs / public

Repository for Wallaby.js questions and issues
http://wallabyjs.com
760 stars 45 forks source link

Allocation failed - JavaScript heap out of memory​​ #1617

Closed daveaspinall closed 6 years ago

daveaspinall commented 6 years ago

Issue description or question

When trying to start wallaby in VS Code it spins up for a while and returns this error:

​​FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory​​
​​ 1: node::Abort() [/Users/xx/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 2: node::OnFatalError(char const*, char const*) [/Users/xx/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/xx/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 4: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/Users/xx/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 5: v8::internal::Runtime_StringBuilderConcat(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/xx/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 6: 0x1de0c6e042fd​​

Any ideas what could be causing this? Fairly straightforward React app running on a dotnet core server.

I've tried adding this to the config file but it didn't make a difference:

{
  ...
  "env": {
    "params": {
      "runner": "--max_old_space_size=4098"
    }
  }
}

Wallaby.js configuration file

module.exports = (wallaby) => {
  return {
    files: [
      'package.json',
      'scripts/beforeTest.js',
      'ClientApp/**/*.js',
      'test/**/*.js',
      '!ClientApp/**/*.test.js',
      '!ClientApp/**/*.stories.js',
      '!test/**/*.test.js',
    ],

    tests: [
      'ClientApp/**/*.test.js',
      'test/**/*.test.js',
    ],

    env: {
      type: 'node',
      runner: 'node',
    },

    compilers: {
      '**/*.js': wallaby.compilers.babel({
        babel: require('babel-core'),
        presets: ['react-app'],
      }),
    },

    testFramework: 'jest',

    setup: (wallaby) => {
      const jestConfig = require('./package.json').jest
      wallaby.testFramework.configure(jestConfig)
    },

    debug: true,
  }
}

Code editor or IDE name and version

Visual Studio Code v1.22.2

OS name and version

macOS High Sierra (10.13.3), running node v9.3.0

ArtemGovorov commented 6 years ago

How large is the ClientApp folder? Does it contain any nested node_modules folders?

daveaspinall commented 6 years ago

@ArtemGovorov thanks for the quick response!

The ClientApp folder has 98 directories, 296 files (860 KB) with no nested node_modules. Would you like me to include the tree view of the folder?

A large bulk of the files are probably .scss files, and we use Redux too.

ArtemGovorov commented 6 years ago

@daveaspinall This is interesting, we have much larger projects running without any issues.

daveaspinall commented 6 years ago

We also have other larger projects running fine which is strange!

Full console output

​​​​​​​​​​0 failing tests, 0 passing​​​​​
​​​​​​​​​​
​​FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory​​
​​ 1: ​​
​​node::Abort() [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​​​
​​ 2: ​​
​​node::OnFatalError(char const*, char const*) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 3: ​​
​​v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 4: ​​
​​v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​​​
​​ 5: ​​
​​v8::internal::Runtime_StringBuilderConcat(int, v8::internal::Object**, v8::internal::Isolate*)​​
​​ [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 6: 0xf2a0d4842fd​​
​​​​
​​node::Abort() [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 2: node::OnFatalError(char const*, char const*) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 4: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 5: ​​
​​v8::internal::Runtime_StringBuilderConcat(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 6: 0x7b2b9c842fd​​
​​​​
​​node::Abort() [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 2: node::OnFatalError(char const*, char const*) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 4: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 5: v8::internal::Runtime_StringBuilderConcat(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 6: 0x171dd59842fd​​
​​​​
​​node::OnFatalError(char const*, char const*) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​​​
​​ 3: ​​
​​v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​​​
​​ 4: ​​
​​v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag)​​
​​ [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 5: ​​
​​v8::internal::Runtime_StringBuilderConcat(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 6: ​​
​​0xe96947042fd​​
​​​​
​​FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory​​
​​ 1: node::Abort() [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 2: node::OnFatalError(char const*, char const*) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 4: ​​
​​v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 5: v8::internal::Runtime_StringBuilderConcat(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​ 6: 0x21ef49e042fd​​
​​​​
​​node::OnFatalError(char const*, char const*) [/Users/daveaspinall/.nvm/versions/node/v9.3.0/bin/node]​​
​​​​
​​ 3: ​​
​​0x865743042fd​​

package.json

{
  "name": "afs",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "build:dev": "cross-env NODE_ENV=development webpack",
    "build": "cross-env NODE_ENV=production webpack",
    "dotnet:dev": "cross-env NODE_ENV=development ASPNETCORE_ENVIRONMENT=Development ASPNETCORE_URLS=http://*:5000 dotnet run --no-launch-profile",
    "dotnet": "cross-env NODE_ENV=production ASPNETCORE_ENVIRONMENT=Production ASPNETCORE_URLS=http://*:5000 dotnet run --no-launch-profile",
    "start": "npm-run-all build:dev dotnet:dev",
    "start:prod": "npm-run-all build dotnet",
    "test": "jest",
    "coverage": "npm test -- --coverage",
    "storybook": "start-storybook -p 9001 -c config/storybook",
    "chromatic": "chromatic test --storybook-addon --app-code wmxsoblvpxj"
  },
  "dependencies": {
    "axios": "^0.18.0",
    "domain-task": "^3.0.3",
    "fontfaceobserver": "^2.0.13",
    "react": "16.2.0",
    "react-dom": "16.2.0",
    "react-helmet": "^5.2.0",
    "react-hot-loader": "3.0.0-beta.7",
    "react-redux": "5.0.5",
    "react-router": "^4.2.0",
    "react-router-dom": "4.1.1",
    "react-router-redux": "5.0.0-alpha.6",
    "react-transition-group": "^2.2.1",
    "redux": "3.7.1",
    "redux-thunk": "2.2.0"
  },
  "devDependencies": {
    "@storybook/addon-info": "^3.2.9",
    "@storybook/react": "^3.2.8",
    "@webpack-blocks/dev-server2": "^0.4.0",
    "@webpack-blocks/webpack": "^1.0.0-rc",
    "@webpack-blocks/webpack2": "^0.4.0",
    "airbnb-js-shims": "^1.4.0",
    "aspnet-prerendering": "^3.0.1",
    "aspnet-webpack": "^2.0.3",
    "aspnet-webpack-react": "^3.0.0",
    "autoprefixer": "^7.1.6",
    "babel-core": "^6.26.0",
    "babel-eslint": "^8.2.2",
    "babel-jest": "22.4.1",
    "babel-loader": "^7.1.3",
    "babel-plugin-dynamic-import-node": "^1.2.0",
    "babel-plugin-syntax-dynamic-import": "^6.18.0",
    "babel-plugin-transform-react-constant-elements": "^6.23.0",
    "babel-plugin-transform-react-inline-elements": "^6.22.0",
    "babel-plugin-transform-react-remove-prop-types": "^0.4.12",
    "babel-preset-react-app": "^3.0.3",
    "case-sensitive-paths-webpack-plugin": "^2.1.1",
    "copyfiles": "^1.2.0",
    "cross-env": "^5.1.1",
    "css-loader": "^0.26.0",
    "cssnano": "^3.10.0",
    "enzyme": "^3.2.0",
    "enzyme-adapter-react-16": "^1.1.0",
    "enzyme-redux": "^0.1.7",
    "eslint": "^4.9.0",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-import-resolver-webpack": "^0.8.1",
    "eslint-loader": "^1.9.0",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^6.0.2",
    "eslint-plugin-react": "^7.0.1",
    "expose-loader": "^0.7.3",
    "extract-text-webpack-plugin": "3.0.2",
    "fetch-mock": "^6.3.0",
    "file-loader": "^1.1.5",
    "fs-extra": "^4.0.2",
    "html-webpack-plugin": "^2.30.1",
    "identity-obj-proxy": "^3.0.0",
    "ignore-loader": "^0.1.2",
    "jest": "22.4.2",
    "json-loader": "^0.5.7",
    "jump.js": "^1.0.2",
    "lazysizes": "^4.0.1",
    "loadable-components": "^1.1.1",
    "node-sass": "^4.7.2",
    "npm-run-all": "^4.1.2",
    "postcss-flexbugs-fixes": "^3.2.0",
    "postcss-loader": "^2.0.8",
    "postcss-responsive-type": "^1.0.0",
    "prop-types": "^15.6.0",
    "raf": "^3.3.2",
    "react-a11y": "^1.0.0",
    "react-autocomplete": "^1.7.2",
    "react-chromatic": "^0.7.1",
    "react-dev-utils": "^4.2.1",
    "react-google-maps": "^9.4.5",
    "react-image-gallery": "^0.8.7",
    "react-waypoint": "^8.0.1",
    "rimraf": "^2.6.2",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.19.0",
    "to-string-loader": "^1.1.5",
    "url-loader": "^0.6.2",
    "webpack": "3.11.0",
    "webpack-blocks-happypack": "^0.2.0",
    "webpack-blocks-split-vendor": "^0.3.1",
    "webpack-dev-server": "^2.11.1",
    "webpack-hot-middleware": "2.21.0",
    "webpack-manifest-plugin": "^1.3.2",
    "webpack-merge": "4.1.0",
    "webpack-node-externals": "^1.6.0"
  },
  "jest": {
    "moduleDirectories": [
      "ClientApp",
      "node_modules"
    ],
    "moduleNameMapper": {
      "^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/config/jest/fileMock.js",
      "\\.(scss|css)$": "identity-obj-proxy"
    },
    "setupFiles": [
      "<rootDir>/scripts/beforeTest.js"
    ]
  }
}

And lastly, running the tests via the CLI yarn test work fine.

ArtemGovorov commented 6 years ago

We also have other larger projects running fine which is strange!

Running with wallaby?

Full console output

Thanks, but this is the output from Wallaby Tests output channel, and I'm after output from the Wallaby.js Console output channel (there should be much more output there):

screen shot 2018-04-16 at 9 47 59 pm
daveaspinall commented 6 years ago

Running with wallaby?

Yea!

I'm after output from the Wallaby.js Console output channel

Ah sorry! Attached the output in a file as it's fairly verbose. Hope this helps.

ArtemGovorov commented 6 years ago

There's something strange going on. From the log file it looks like wallaby is successfully processing all files, but when running Jest, the OOM exception is thrown, presumably because some huge string is being created somewhere (for some reason).

I'm not sure what could be causing it, but I have a suspicion that the issue can even be reproduced without any real tests.

Please try the following:

ArtemGovorov commented 6 years ago

Also, given that according to the log file, the OOM occurs in every test runner process, it may happen because of something in scripts/beforeTest.js. Is there anything in the file that you suspect may cause the issue? May be worth trying commenting things out in it to see if it let's wallaby start or not.

daveaspinall commented 6 years ago

@ArtemGovorov wow, thanks for all the recommendations!

beforeTests.js contains:

import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

// set up adapter for enzyme
configure({ adapter: new Adapter() })

Okay so, I've tried the following but we still have the memory issue:

I'll work on copying the repo at lunch today for you. Did you want all the files leaving in, but just emptying?

Thanks for the help on this!

ArtemGovorov commented 6 years ago

Okay so, I've tried the following but we still have the memory issue:

Awesome, thanks.

I'll work on copying the repo at lunch today for you. Did you want all the files leaving in, but just emptying?

Whatever is easier for you to share - as soon as we get a repo where we can reproduce the issue, it should be pretty straightforward to investigate from there.

daveaspinall commented 6 years ago

@ArtemGovorov I've found the issue!

Okay so in our project we have a wwwroot directory where all the dist files are build into from webpack. While cleaning out the duplicate repo I found 500+ vendor and client bundles (the task to clean out the folder wasn't working). This will have been what was causing the memory issue...!

Thank you for your help in directing me to the problem, and sorry for partly wasting your time as it wasn't wallaby.js that was the issue 😅

ArtemGovorov commented 6 years ago

Ah, good find, thanks for the update!