Description
- Version:v10.9.0
- Platform:Linux station-name 4.15.0-1023-azure Simple project messaging. #24-Ubuntu SMP Tue Aug 28 17:35:08 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
- Subsystem: Not known
Hello all,
I'm noticing a tricky issue that may be hard to explain. At a high level, it seems as though require()
struggles with recently moved/renamed files.
I'm seeing this issue when trying to require some functions from files within the same folder. I have three files, two with identical contents (ctrl-a, ctrl-c, ctrl-v
between files) in the same folder: a.js
, copy-of-a.js
, and b.js
. I require functions from these files elsewhere with the following code:
const {someFunction, someOtherFunction, etc} = require('../../middlewares/a.js')
Both a.js
and copy-of-a.js
have functions required in b.js
and vice versa: b.js
has some functions required in a.js
and copy-of-a.js
. All paths are correct, as no errors are seen for missing files.
Here's where things get weird. Calling a function in b.js
that itself uses a requires function from a.js
will yield an error stating TypeError: someFunction is not a function
along with the stack trace of where the error occurred. Updating the code to require the same function from copy-of-a.js
instead works just fine.
I'm not sure that I have can do to provide more information about this behavior. All I can think of is that I had recently run the following command to rename a.js
from something else:
mv someOldName.js a.js
Even this is theory is thin. Refactoring the require()
from other files to point to the new name works just fine. In my eyes the only difference between the two a
files is that one is brand new and the other one has been around for a while.
Any suggestions on how to provide more information to properly see where the issue may lay?
Thanks!