Experience-Monks / Experience-Monks/babel-plugin-static-fs

fs is not defined when wrapped inside promisify

Open
#19 1 comment 1 reaction 0 assignees View on GitHub
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.