istanbuljs / nyc

the Istanbul command line interface
https://istanbul.js.org/
ISC License
5.55k stars 353 forks source link

Maximum call stack size exceeded at /.../append-transform@2.0.0 #1521

Closed hverlin closed 1 year ago

hverlin commented 1 year ago

Issue

I am getting the following error when running our tests with nyc:

Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
    at /.../append-transform@2.0.0/node_modules/append-transform/index.js:49:19
    at /.../append-transform@2.0.0/node_modules/append-transform/index.js:64:4
    at /.../append-transform@2.0.0/node_modules/append-transform/index.js:64:4
    at /.../append-transform@2.0.0/node_modules/append-transform/index.js:64:4
    at /.../append-transform@2.0.0/node_modules/append-transform/index.js:64:4
    at /.../append-transform@2.0.0/node_modules/append-transform/index.js:64:4
    at ...

Sorry, I don't know how to create a simple example to reproduce this issue. This happens sporadically in our pipeline. I am mainly interested if anyone has any idea of what might be going on. It looks like it's an issue with Babel so not sure if it's even the correct repository to report against as well. (not sure if it's an issue on how Istanbul is supposed to be used, the way istanbul calls babel? or babel itself) or something else.

Here is basically how NYC is invoked in for our tests.

async function setupCoverage({ reportDir }) {
  const NYC = require('nyc');

  // use a similar configuration as the nyc command line
  const nyc = new NYC({
    reporter: ['text-summary'],
    cwd: process.cwd(),
    autoWrap: true,
    parserPlugins: [
      'asyncGenerators',
      'bigInt',
      'classProperties',
      'classPrivateProperties',
      'classPrivateMethods',
      'dynamicImport',
      'importMeta',
      'numericSeparator',
      'objectRestSpread',
      'optionalCatchBinding',
      'topLevelAwait',
    ],
    excludeNodeModules: true,
    exclude: [
      'coverage/**',
      'packages/*/test{,s}/**',
      '**/*.d.ts',
      'test{,s}/**',
      'test{,-*}.{js,cjs,mjs,ts,tsx,jsx}',
      '**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}',
      '**/__tests__/**',
      '**/{ava,babel,nyc}.config.{js,cjs,mjs}',
      '**/jest.config.{js,cjs,mjs,ts}',
      '**/{karma,rollup,webpack}.config.js',
      '**/.{eslint,mocha}rc.{js,cjs}',
    ],
    hookRequire: true,
    tempDirectory: path.join(reportDir, '.nyc_output'),
  });

  // this is what the nyc command line does unless one uses --clean
  await nyc.createTempDirectory();

  // https://github.com/istanbuljs/nyc/blob/master/bin/nyc.js#L51
  process.env.BABEL_DISABLE_CACHE = '1';
  nyc.wrap();

  return nyc;
}

const nyc =  await setupCoverage({ reportDir: path.join(path.dirname(outputFilePath)) });

const mocha = new Mocha({ fullTrace: true, reporter: 'xunit'  });
mocha.addFile(TEST_PATH);

const runner = mocha.run(async failures => {
  mocha.dispose();

  await nyc.writeProcessIndex();
  nyc.writeCoverageFile();
  nyc.maybePurgeSourceMapCache();

  await nyc.report().then(() => console.log(`*** Worker ${process.pid} - done reporting.`));
})

Expected Behavior

Should not get Maximum call stack size exceeded

Observed Behavior

Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
    at /.../append-transform@2.0.0/node_modules/append-transform/index.js:49:19
    at /.../append-transform@2.0.0/node_modules/append-transform/index.js:64:4
    at /.../append-transform@2.0.0/node_modules/append-transform/index.js:64:4
    at /.../append-transform@2.0.0/node_modules/append-transform/index.js:64:4
    at /.../append-transform@2.0.0/node_modules/append-transform/index.js:64:4
    at /.../append-transform@2.0.0/node_modules/append-transform/index.js:64:4
    at ...

Troubleshooting steps

Open to suggestions on which options I should play with.

Environment Information

Ubuntu 20
nyc: 15.1
Node: 16.14
npm: 8.3.1
hverlin commented 1 year ago

Used c8 instead: https://github.com/bcoe/c8