babel-plugin-static-fs
babel-plugin-static-fs copied to clipboard
fs is not defined when wrapped inside promisify
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);
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
.