You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Platform: Darwin tingyuandeMacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64
Subsystem: no
What steps will reproduce the bug?
Just run this code:
constfs=require('fs')constpath=require('path')constjsonFile=path.resolve('./test.json')if(fs.existsSync(jsonFile)){fs.unlinkSync(jsonFile)}try{consta=require(jsonFile)console.log('test1',a)}catch(e){// throw error, it is correct, cause jsonFile not exists.console.log('test error1: ',e.message)}fs.writeFileSync(jsonFile,JSON.stringify({name: 'test'},null,2))try{consta=require(jsonFile)console.log('test2',a)}catch(e){// still throw error, but jsonFile has exists.console.log('test error2: ',e.message)}Promise.resolve().then(()=>{try{consta=require(jsonFile)console.log('test3',a)}catch(e){// no more error.console.log('test error3: ',e.message)}})
How often does it reproduce? Is there a required condition?
No condition, 100% occurs.
What is the expected behavior?
First require call, it is reasonable to throw error, but with second require call, there is should no error.
What do you see instead?
Error throwed when second calling require.
Additional information
I think this issue is caused by incorrect statCache process, see Module._findPath in modules/cjs/loader.js.
The text was updated successfully, but these errors were encountered:
lovetingyuan
changed the title
require file which not exists and create it latter and call require the file will throw Cannot find module error
require file which not exists and create it latter and call require the file again will throw Cannot find module error
Jul 1, 2021
That looks like a duplicate of #36638. The fix is unlikely to be backported to v14.x as it would be potentially breaking for folks who expects this behavior.
What steps will reproduce the bug?
Just run this code:
How often does it reproduce? Is there a required condition?
No condition, 100% occurs.
What is the expected behavior?
First require call, it is reasonable to throw error, but with second require call, there is should no error.
What do you see instead?
Error throwed when second calling require.
Additional information
I think this issue is caused by incorrect
statCache
process, seeModule._findPath
inmodules/cjs/loader.js
.The text was updated successfully, but these errors were encountered: