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
This may very well be a compiler bug, but I'm not sure how to use tsc to reproduce this.
I suspect this is a compiler issue yes. That said there may be good reason for it. I'd suggest asking a question on the Typescript project to confirm if this is expected behaviour or not. ts-loader is doing nothing special here; just hooking into the Typescript compiler API
I think I understand it now. I think it has to do with the fact that transpileOnly uses ts.transpileModule, which is essentially equivalent to turning on isolatedModules. When compiling each module separately, the compiler does not have enough information to know whether an import is a type or not (see microsoft/TypeScript#15231), so while it eliminates imports that are never used in a value position (which works for imported types that are not exported), it cannot know whether an export is a type or not. So, fundamentally, ts.transpileModule is incompatible with type re-exports.
This issue has cropped up now because webpack 4 warns about these invalid exports, but the final bundle otherwise works fine. Perhaps there's an option in webpack to silence these warnings?
ersinakinci, miracle2k, skovy, himanshujariyal, Bnaya and 6 moreMarkSalabutin
Thanks for investigating and reporting back - super helpful! It might be worth inquiring against the webpack repo for such an option and linking back to this. I'm not aware of an option myself but that doesn't mean it doesn't exist!
When transpileOnly is enabled, ts-loader leaves in re-exports of types, causing webpack 4 to warn about export not being found · Issue #751 · TypeStrong/ts-loader
Activity
johnnyreilly commentedon Mar 24, 2018
I suspect this is a compiler issue yes. That said there may be good reason for it. I'd suggest asking a question on the Typescript project to confirm if this is expected behaviour or not. ts-loader is doing nothing special here; just hooking into the Typescript compiler API
univerio commentedon Mar 26, 2018
I think I understand it now. I think it has to do with the fact that
transpileOnly
usests.transpileModule
, which is essentially equivalent to turning onisolatedModules
. When compiling each module separately, the compiler does not have enough information to know whether an import is a type or not (see microsoft/TypeScript#15231), so while it eliminates imports that are never used in a value position (which works for imported types that are not exported), it cannot know whether an export is a type or not. So, fundamentally,ts.transpileModule
is incompatible with type re-exports.This issue has cropped up now because webpack 4 warns about these invalid exports, but the final bundle otherwise works fine. Perhaps there's an option in webpack to silence these warnings?
johnnyreilly commentedon Mar 26, 2018
Thanks for investigating and reporting back - super helpful! It might be worth inquiring against the webpack repo for such an option and linking back to this. I'm not aware of an option myself but that doesn't mean it doesn't exist!
univerio commentedon Mar 26, 2018
Found the option:
Perhaps we can add it to the readme?
johnnyreilly commentedon Mar 27, 2018
Sure - send a PR!
Add a tip about suppressing "export not found" warnings for transpile…
Add a tip about suppressing "export not found" warnings for transpile…
FourwingsY commentedon Apr 11, 2018
Hi, I met this problem not as warning but as error.
So I cannot suppress it. Anybody has an idea?
univerio commentedon Apr 11, 2018
@FourwingsY Do you have a plugin that converts warnings into errors?
FourwingsY commentedon Apr 11, 2018
@univerio Oh yes i got it. I've set
config.module.strictExportPresence = true
on webpack config. Thanks a lot!enoshixi commentedon Jun 25, 2018
This also works for me and gets the compiler to remove the type export all together:
22 remaining items