buffer icon indicating copy to clipboard operation
buffer copied to clipboard

"File is not a constructor" in Node 16 and below

Open jeswr opened this issue 2 years ago • 2 comments

I have the following index.js

const { File } = require('buffer');
console.log(new File(['Hello World'], 'hello.txt'))

node index succeeds on Node v20.0.0 and v18.16.0.

node index fails with the following error on Node v16.20.0 and v14.21.3

console.log(new File(['Hello World'], 'hello.txt'))
            ^

TypeError: File is not a constructor
    at Object.<anonymous> (/home/jeswr/Documents/GitHub/buffer-file-test/index.js:2:13)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
    at Module.load (node:internal/modules/cjs/loader:1074:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47

Versions buffer: 6.0.3

jeswr avatar May 18 '23 13:05 jeswr

Did you get any solution for this?

Yash-Dalvi avatar Aug 01 '24 09:08 Yash-Dalvi

No I did not, though not sure if this is particularly important now that Node 18 is deprecated.

@NSeydoux is this still a problem for solid-client?

jeswr avatar Aug 01 '24 10:08 jeswr