(node:75246) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
at maybeCallback (fs.js:127:9)
at Object.writeFile (fs.js:1123:14)
at fsp.access.then.catch (/Users/owo3732/random/fsnode/index.js:14:8)
(node:75246) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:75246) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
What am I doing wrong?
Edit: I tried rewriting this. I think the return new Promise bit was unnecessary
Yes, the problem was that I copied and pasted your code and stuck it in the function but did not use the return keyword in front of fsp.access('./.npmignore', fs.constants.F_OK)
What difference does it make to the code whether you do or don’t return fsp.writeFile(err.path, stuffToIgnore)?
Well fs.promises.writeFile() gives you a promise, which you have to return if you want to chain additional handlers to npmIgnore(); otherwise it would just return undefined.
Hm just had to look that up too, it seems that the ENOENT condition is indeed redundant as the F_OK mode only checks for the file’s very existence (see here).