Skip to content

fix(webpack5): Remove 'ts-loader' from webpack 'javascript' configuration #9715

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

Closed
wants to merge 9 commits into from

Conversation

CatchABus
Copy link
Contributor

@CatchABus CatchABus commented Dec 25, 2021

PR Checklist

What is the current behavior?

If there is an attempt to use a plugin dynamic import inside a JavaScript app, one will receive errors about tsconfig.json being missing as webpack will use lazy loading and try to load typescript definition files inside plugin.

Specifically, it occurs when the require path itself is dynamic:

var suffix = "messaging";
import(`firebase-${suffix}`);

Perhaps, this can be solved by creating a tsconfig.json file but the point is that JavaScript apps should not bother with TS files and developers should not worry about TypeScript setup.
Still, plugins include TS definition files and that confuses webpack in NS JavaScript apps.

What is the new behavior?

New behaviour will remove ts-loader if developers declare they use javascript configuration in webpack.

Old webpack plugin excluded ts-loader from webpack.javascript.config file but it seems that webpack5 makes sure most kinds of apps inherit it.

@cla-bot cla-bot bot added the cla: yes label Dec 25, 2021
@CatchABus CatchABus marked this pull request as draft December 25, 2021 01:06
@CatchABus CatchABus marked this pull request as ready for review December 25, 2021 01:14
@CatchABus CatchABus marked this pull request as draft December 25, 2021 01:42
@CatchABus CatchABus marked this pull request as ready for review December 25, 2021 04:13
@CatchABus CatchABus changed the title fix: Exclude typescript definition files from ts-loader fix: Remove 'ts-loader' for webpack 'javascript' configuration Dec 25, 2021
@CatchABus CatchABus changed the title fix: Remove 'ts-loader' for webpack 'javascript' configuration fix: Remove 'ts-loader' from webpack 'javascript' configuration Dec 25, 2021
@CatchABus CatchABus changed the title fix: Remove 'ts-loader' from webpack 'javascript' configuration fix(webpack5): Remove 'ts-loader' from webpack 'javascript' configuration Jan 4, 2022
@rigor789
Copy link
Member

rigor789 commented Feb 17, 2022

// todo: perhaps we can provide a default tsconfig
// and use that if the project doesn't have one?
// configFile: '',

Maybe it would make sense to provide a default config in those cases - my thinking here is that js projects can still benefit from occasionally using a ts file here & there.

Alternatively, we can move the declaration to the when has typescript block:

// Use Fork TS Checker to do type checking in a separate non-blocking process
config.when(hasDependency('typescript'), (config) => {
config
.plugin('ForkTsCheckerWebpackPlugin')
.use(ForkTsCheckerWebpackPlugin, [
{
async: !!env.watch,
typescript: {
memoryLimit: 4096,
},
},
]);
});

@rigor789 rigor789 self-assigned this Feb 17, 2022
@rigor789 rigor789 added this to the 8.2 milestone Feb 17, 2022
@NathanWalker NathanWalker removed this from the 8.2 milestone Nov 29, 2022
@CatchABus CatchABus closed this Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants