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

Viewed 7286

Our build environment currently uses node 12.19.0 and npm 6.14.8. When I saw that the new LTS version of node 14.15.1 (still npm 6.14.8) was available I downloaded it and ran our webpack build script and received this error. Is the new version of node complaining about an error that was always there, but ignored by 12.19.0?

internal/fs/utils.js:781
  throw new ERR_INVALID_ARG_TYPE(
  ^

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
    at writeFile (fs.js:1436:5)
    at go$writeFile (/Components/node_modules/graceful-fs/graceful-fs.js:131:14)
    at Object.writeFile (/Components/node_modules/graceful-fs/graceful-fs.js:128:12)
    at /Components/node_modules/jest-html-reporter/dist/main.js:47:13
    at /Components/node_modules/mkdirp/index.js:48:26
    at callback (/Components/node_modules/graceful-fs/polyfills.js:295:20)
    at FSReqCallback.oncomplete (fs.js:184:5) {
  code: 'ERR_INVALID_ARG_TYPE'
}
2 Answers

Add a second argument to writeFileSync

Instead of:

fs.writeFileSync(`${folderName}/styles.css`);

Do this:-

fs.writeFileSync(`${folderName}/styles.css`, '');

It tells wfs what to write to the file. It can be left empty

Uplift jest-html-reporter version to at least 3.1.3

Related