Description
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 commentedon May 1, 2018
Fixed by #262
Thanks!
Bump dep, fix gruntjs/grunt-contrib-jasmine#266
Bump dep, fix gruntjs/grunt-contrib-jasmine#266
Replaced unlink by unlinkSync gruntjs/grunt-contrib-jasmine#266
hidaytrahman commentedon Feb 26, 2019
Make changes on both files below
\node_modules\grunt-contrib-jasmine\tasks\ jasmine.js
Replace
unlink
withunlinkSync
\node_modules\grunt-lib-phantomjs\lib\ phantomjs.js
Replace tempfile.
unlink
with tempfile.unlinkSync
daksh23 commentedon Mar 14, 2019
thanks
is work!!!!!
askaaqib commentedon Mar 30, 2019
thank @hidaytrahman it worked for me. changed my node v9.11.0 to v10.13.0
Callback must be a function
when using a custom tagged template grammar gandm/language-babel#525