-
-
Notifications
You must be signed in to change notification settings - Fork 433
When transpileOnly is enabled, ts-loader leaves in re-exports of types, causing webpack 4 to warn about export not being found #751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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 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? |
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! |
Found the option: {
stats: {
warningsFilter: /export .* was not found in/,
}
} Perhaps we can add it to the readme? |
Sure - send a PR! |
Hi, I met this problem not as warning but as error. |
@FourwingsY Do you have a plugin that converts warnings into errors? |
@univerio Oh yes i got it. I've set |
This also works for me and gets the compiler to remove the type export all together: import { IFoo } from "./foo";
export type IFoo = IFoo; |
That did not work for me, but the solution in babel/babel-loader#603 (comment) did: import { T as a_T } from "./a";
export type T = a_T; |
I'm seeing this now in webpack
Not sure if this is a result of the version of webpack, typescript, or maybe some munging from create-react-app. |
^^ To avoid a DenverCoder9 situation, here's an update. The example For whatever reason, the warning I posted above is not what you should be basing your regex on. Since the actual warning vs what was being displayed are different strings.
|
This is going to be an issue when using any compiler that has to work without having the full type information... like typescript itself in |
I've reopened this issue following @MLoughry comments on the webpack 5 beta. It seems this issue may present with webpack 5 as maybe an error whereas with webpack 4 it's a warning. See webpack/webpack#9802 (comment) If people could detail:
That would be helpful. It's not clear to me that the problems being experienced can be solved by ts-loader. Any "fix" would likely need to be implemented within the TypeScript APIs or handled by webpack configuration. I'm reopening this ticket for visibility and in the hope that people can use this as a place to discuss the issues. If people could comment that would be amazing. As it is, |
See microsoft/TypeScript#34750 also as suggested by @andrewbranch |
it's possible to re-export types: export type ExternalArgs = import("./internal/interfaces").ExternalArgsApi;
export type CreateObjectBufferOptions = import("./internal/api").CreateObjectBufferOptions; |
should be set config.module.strictExportPresence = false |
With microsoft/TypeScript#35200 (comment) merged I wonder if we should consider changing the default
For webpack 5 given that:
I think this might resolve the issue reported here so most users just don't bump into it. We'd look to do this as a breaking changes version if we did. A little background: as policy we deliberately don't change the default compiler flags often so that ts-loader can generally be treated as a drop in replacement for ts-loader/src/compilerSetup.ts Lines 59 to 63 in 37a0731
I'd be interested in your thoughts @andrewbranch ? |
I don’t think you need to change the default. You can still do |
Yeah that seems reasonable. I may put some docs in ts-loader to explicitly recommend using one of those too. Happy New Decade by the way! 🥰🤗 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Closing as stale. Please reopen if you'd like to work on this further. |
Expected Behaviour
For a project like this:
Regardless of whether
transpileOnly
is enabled, the output for bar.ts should be (assuming module=ESNEXT):Actual Behaviour
The actual output is:
which causes webpack to complain:
When
transpileOnly
is off, the module is correctly emitted. This may very well be a compiler bug, but I'm not sure how to usetsc
to reproduce this.Steps to Reproduce the Problem
Location of a Minimal Repository that Demonstrates the Issue.
https://github.com/univerio/ts-loader-type-export-issue
The text was updated successfully, but these errors were encountered: