Experience-Monks / Experience-Monks/babel-plugin-static-fs
fs is not defined when wrapped inside promisify
- Dominant language
- JavaScript
- Stars
- 35
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
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);
Contributor guide
Research direction
Start with the test.js example and reproduce the transformation using npx babel --plugins=babel-plugin-static-fs test.js, then compare the generated out.js with the input. Trace why the fs require is removed when fs.writeFile is passed to promisify; done means the transformed output retains a valid fs reference and no longer raises fs is not defined.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100