isaacs / node-graceful-fs

fs with incremental backoff on EMFILE
ISC License
1.27k stars 148 forks source link

fs.writeFile: after node upgrade to 14, throws TypeError [ERR_INVALID_ARG_TYPE] #211

Closed ywang-temp closed 2 years ago

ywang-temp commented 3 years ago

https://github.com/isaacs/node-graceful-fs/blob/master/graceful-fs.js#L139

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of XMLElement

skylerbrady commented 3 years ago

Have you found any solution for this issue? because I'm facing the same!

ywang-temp commented 3 years ago

no..

rooterkyberian commented 3 years ago

I have seen this error in context of cypress (after upgrade to node 14 from 10) - not sure if its and error of this library or just indication it was used badly

TypeError [ERR_INVALID_ARG_TYPE] [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
    at writeFile (fs.js:1436:5)
    at go$writeFile (/root/.cache/Cypress/7.3.0/Cypress/resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:106:14)
    at writeFile (/root/.cache/Cypress/7.3.0/Cypress/resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:103:12)
    at go$writeFile (/root/.cache/Cypress/7.3.0/Cypress/resources/app/packages/server/node_modules/fs-extra/node_modules/graceful-fs/graceful-fs.js:139:14)
    at Object.writeFile (/root/.cache/Cypress/7.3.0/Cypress/resources/app/packages/server/node_modules/fs-extra/node_modules/graceful-fs/graceful-fs.js:136:12)
    at /root/.cache/Cypress/7.3.0/Cypress/resources/app/packages/server/node_modules/fs-extra/lib/output/index.js:18:27
    at /root/.cache/Cypress/7.3.0/Cypress/resources/app/packages/server/node_modules/universalify/index.js:23:46
 {
  code: 'ERR_INVALID_ARG_TYPE'
}
rooterkyberian commented 3 years ago

In our case problem was just as an error said - we had a line in our code Cypress.backend("write:file", "marker"); which is in fact missing the 3rd argument - the data just like traceback said and like other reports suggest https://stackoverflow.com/questions/65137938/typeerror-err-invalid-arg-type-the-data-argument-must-be-of-type-string-or .

So, yea, nodejs fs started to check the data type more diligently, but that wasn't an issue in node-graceful-fs itself.

abnerlee commented 3 years ago

same for open and other methods

crossz commented 3 years ago

same here:

throw error 1 times
TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
    at Object.writeFile (fs.js:1487:5)
isaacs commented 2 years ago

This is not a graceful-fs bug. The consuming library is passing an invalid argument (ie, not a String or Buffer) to fs.writeFile, which node 14 no longer allows. (Prior to node 14, it'd coerce to a string, so fs.writeFile(path, undefined) would write the string 'undefined' for example. Writing an object would call that object's toString() method.)

This must be fixed in the calling code.