avajs / ava

Node.js test runner that lets you develop with confidence 🚀
MIT License
20.74k stars 1.41k forks source link

Internal error in ava/lib/fork.js when running ava #2419

Closed miohtama closed 4 years ago

miohtama commented 4 years ago

I am trying to set up Ava tests for my TypeScript project. So far, I have managed to install dependencies and create a config file ava.config.js.

But after creating the config file I get the following Internal error when running ava. It should probably give some more clueful error message and terminate the process nicely.

npx ava -v  
  ✖ Couldn't find any files to test

  ✖ Internal error
  TypeError: Cannot read property 'on' of null
  TypeError: Cannot read property 'on' of null
      at module.exports (/Users/moo/code/dawn-erc20/node_modules/ava/lib/fork.js:40:20)
      at pMap (/Users/moo/code/dawn-erc20/node_modules/ava/lib/api.js:225:20)
      at /Users/moo/code/dawn-erc20/node_modules/p-map/index.js:57:21
      at process.internalTickCallback (internal/process/next_tick.js:77:7)

  ✖ Internal error
  TypeError: Cannot read property 'on' of null
  TypeError: Cannot read property 'on' of null
      at module.exports (/Users/moo/code/dawn-erc20/node_modules/ava/lib/fork.js:40:20)
      at pMap (/Users/moo/code/dawn-erc20/node_modules/ava/lib/api.js:225:20)
      at /Users/moo/code/dawn-erc20/node_modules/p-map/index.js:57:21
      at process.internalTickCallback (internal/process/next_tick.js:77:7)

Also the ava command hangs, so I need to terminate it with CTRL+C.

My ava.config.js


// AVA configuration https://github.com/avajs/ava/blob/master/docs/06-configuration.md
export default ({projectDir}) => {

    return {
        "typescript": {
            "rewritePaths": {
        "src/": "build/",
        "test/": "build/test/",
            }
        }
    }
}
npx ava --version
3.5.0
miohtama commented 4 years ago

I poked the internals. It was failing on child_process.fork. I tried to add some console output around it why it happens. However, looks like the rabbit hole was running deep and was full of snakes.

Then I decided to push my luck and upgraded Node v11.0.0 -> v12.16.1.

The problem is gone and the error message is now

[~/code/dawn-erc20]% npx ava

  ✖ No tests found in tests/ava.ts

  1 uncaught exception

  Uncaught exception in tests/ava.ts

  /Users/moo/code/dawn-erc20/tests/ava.ts:1
  import test from 'ava';
  ^^^^^^

  SyntaxError: Cannot use import statement outside a module

Back to the right track! Thank you for an awesome open source project.

jerrychong25 commented 3 years ago

In my case, I upgraded Node.js version from 10.0.0 to 12.18.1, then able to fix this Ava Internal Error issue.