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
tsFile.ts and jsFile.js are cyclical dependencies.
When the 'fail' version of the code runs, doSomethingInTsFile() inside of tsFile.ts is undefined.
Looking at the source code for __importStar it becomes clear what is happening: the reference returned from require(...) is replaced with a new container object. It is unclear to me why this occurs and instead the original isn't used, but I suspect its related to emitting code that will ultimately work with other code that goes looking for a 'default' export in that output.
I would chalk this up to me misusing import * or other settings being incorrect, but if the cyclical dependency is removed, then the module imports just fine with an import *. It's this differing behaviour that leads me to think there is a bug here. We encountered this in our project when some code that rarely ran failed at runtime because a cyclical dependency had been added elsewhere that ultimately caused the member functions of the imported library (old commonjs code) to be undefined.
The text was updated successfully, but these errors were encountered:
VeriClock-Bryce
changed the title
__importStar can result in undefined imports with cyclical dependencies
__importStar can result in undefined imports when importing cyclical dependencies
May 15, 2020
I've run across what appears to be a bug with __importStar when cyclical dependencies are involved.
I've replicated the issue this sandbox:
https://codesandbox.io/s/eloquent-khayyam-nn14o?file=/src/tsFile.ts
Which contains 3 key files:
index.js
tsFile.ts
jsFile.js
tsFile.ts and jsFile.js are cyclical dependencies.
When the 'fail' version of the code runs, doSomethingInTsFile() inside of tsFile.ts is undefined.
Looking at the source code for __importStar it becomes clear what is happening: the reference returned from require(...) is replaced with a new container object. It is unclear to me why this occurs and instead the original isn't used, but I suspect its related to emitting code that will ultimately work with other code that goes looking for a 'default' export in that output.
I would chalk this up to me misusing import * or other settings being incorrect, but if the cyclical dependency is removed, then the module imports just fine with an import *. It's this differing behaviour that leads me to think there is a bug here. We encountered this in our project when some code that rarely ran failed at runtime because a cyclical dependency had been added elsewhere that ultimately caused the member functions of the imported library (old commonjs code) to be undefined.
The text was updated successfully, but these errors were encountered: