-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed
Labels
moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.
Description
- Version: 15.5.0
- Platform: Windows 10 x64
- Subsystem: fs, cjs modules
What steps will reproduce the bug?
It seems there may be some race conditions.
Error (cannot find module...):
const fs = require('fs');
try { require('./test.json'); } catch (err) {}
fs.writeFileSync('test.json', '[]');
console.log(require('./test.json'));
With timeout — OK:
const fs = require('fs');
try { require('./test.json'); } catch (err) {}
fs.writeFileSync('test.json', '[]');
setTimeout(() => { console.log(require('./test.json')); }, 1000);
With callback — OK:
const fs = require('fs');
try { require('./test.json'); } catch (err) {}
fs.writeFile('test.json', '[]', () => { console.log(require('./test.json')); });
Promisified — OK:
const fs = require('fs/promises');
try { require('./test.json'); } catch (err) {}
(async function(path) {
await fs.writeFile('test.json', '[]');
console.log(require('./test.json'));
})();
Without failed try — OK:
const fs = require('fs');
fs.writeFileSync('test.json', '[]');
console.log(require('./test.json'));
Previously reported in nodejs/help#3144
Metadata
Metadata
Assignees
Labels
moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.