babel-plugin-static-fs icon indicating copy to clipboard operation
babel-plugin-static-fs copied to clipboard

fs is not defined when wrapped inside promisify

Open cjroebuck opened this issue 5 years ago • 1 comments

The const fs = require('fs') line gets stripped when using fs inside a function, (in this case promisify), leading to fs is not defined error:

test.js:

const fs = require("fs");
const { promisify } = require("util");
const writeFileAsync = promisify(fs.writeFile);`

npx babel --plugins=babel-plugin-static-fs test.js > out.js

out.js:

const {promisify} = require("util");
const writeFileAsync = promisify(fs.writeFile);

cjroebuck avatar Aug 01 '19 00:08 cjroebuck

I am having to discard this plugin until this issue is fixed, hopefully soon I get some time to look into it myself... but just to make a note:

Node >=10.x.x has support for fs.promises. This means that going forward, this plugin will need to support import { promises as fs } from 'fs' and similar syntax. Solving that problem might solve this problem as well, as it will remove our dependence on promisify.

soulofmischief avatar Sep 22 '19 20:09 soulofmischief