Skip to content

"Fatal error: Callback must be a function" with Node 10 #266

Closed
@rudidude86

Description

@rudidude86

After upgrading to Node 10, I started seeing this error when trying to run my grunt jasmine task:

Fatal error: Callback must be a function

After a little debugging, it seems like it's related to unlinking the outfile in the teardown function:

    if (!options.keepRunner && fs.statSync(options.outfile).isFile()) {
      fs.unlink(options.outfile);
    }

I'm not positive, but it looks like Node 10 started emitting JavaScript errors in a few more situations than it used to -- in this case throwing an error because the second argument to fs.unlink() is null, when it's supposed to be a function.

It seems like switching fs.unlink() to fs.unlinkSync() is a quick and easy way to fix the Node 10 issue, and is probably what was intended anyways. (Alternatively, this function could also be refactored to try to do both the outfile unlink and the jasmine.cleanTemp(cb); call asynchronously, but then you have to figure out when the right time to call cb() is... and my multiple-asyncs-without-promises-fu isn't up for that challenge at the moment).

Proposed change:

    if (!options.keepRunner && fs.statSync(options.outfile).isFile()) {
      fs.unlinkSync(options.outfile);
    }

It looks like fs.unlinkSync() has been in Node since v0.1.21, so it should be pretty safe to swap this out. I've personally tested this change on my own project locally with NVM using the following Node versions, and everything seems to be working properly for me:

  • v4.9.1
  • v6.14.1
  • v8.11.1
  • v9.4.0
  • v10.0.0

Activity

rudidude86

rudidude86 commented on May 1, 2018

@rudidude86
Author

Fixed by #262

Thanks!

hidaytrahman

hidaytrahman commented on Feb 26, 2019

@hidaytrahman

Make changes on both files below

\node_modules\grunt-contrib-jasmine\tasks\ jasmine.js
Replace unlink with unlinkSync

\node_modules\grunt-lib-phantomjs\lib\ phantomjs.js
Replace tempfile.unlink with tempfile.unlinkSync

daksh23

daksh23 commented on Mar 14, 2019

@daksh23

thanks

unlinkSync

is work!!!!!

askaaqib

askaaqib commented on Mar 30, 2019

@askaaqib

thank @hidaytrahman it worked for me. changed my node v9.11.0 to v10.13.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @rudidude86@hidaytrahman@askaaqib@daksh23

        Issue actions

          "Fatal error: Callback must be a function" with Node 10 · Issue #266 · gruntjs/grunt-contrib-jasmine