davidmarkclements / 0x

πŸ”₯ single-command flamegraph profiling πŸ”₯
MIT License
3.23k stars 106 forks source link

Error: 0x/lib/random-require.js returned an empty RegExp string #207

Closed qinyang912 closed 5 years ago

qinyang912 commented 5 years ago

macos 10.14.2 node 10.5.0 0x version 4.7.2

Error: 0x/lib/random-require.js returned an empty RegExp string. This may be because of interference in the child process. One known cause is Tap tests with coverage enabled on Node 8.
    at ticksToTree (/Users/qinyang/npm/lib/node_modules/clinic/node_modules/0x/lib/ticks-to-tree.js:40:11)
    at analyse (/Users/qinyang/npm/lib/node_modules/clinic/node_modules/@nearform/flame/analysis/index.js:44:17)

I'm using clinic, but clinic depends on 0x. I found the code in the lib/ticks-to-tree.js file

  // Spawn a file that throws an error to get the loading stack.
  // Then create a regular expression that matches all those files.
  const stackArgs = ['--experimental-modules', '--no-warnings', join(__dirname, 'loading-stacks')]
  let stackChild = spawnSync(pathToNodeBinary, stackArgs)
  if (stackChild.stderr.toString().includes('--experimental-modules')) {
    // Future proof to make sure it works even if the `experimental-modules` flag is removed.
    stackArgs.shift()
    stackChild = spawnSync(pathToNodeBinary, stackArgs)
  }
  const stackRegExpStr = stackChild.stdout.toString()
  if (!stackRegExpStr) {
    throw new Error('0x/lib/random-require.js returned an empty RegExp string. This may be ' +
    'because of interference in the child process. One known cause is Tap tests with coverage enabled on Node 8.')
  }
  const regExp = new RegExp(stackRegExpStr)

if the experimental-modules argument is provided, then stackChild.stdout will get an empty buffer, but after I removed experimental-modules from stackArgs, it work well

mcollina commented 5 years ago

Can you please try updating your Node.js version? This should be working well on the latest LTS. If not, can you please add the script you are using to cause this error?

qinyang912 commented 5 years ago

@mcollina πŸ‘ πŸ‘ πŸ‘ πŸ‘ πŸ‘ I update Node.js to 10.15.0,It work well