Skip to content

swc-loader: allow node_modules .ts and .tsx files #1825

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

darrenjaneczek
Copy link

@darrenjaneczek darrenjaneczek commented May 21, 2025

What this PR does / why we need it:

It can be convenient to use github imports between private repositories in order to share typescript files.
The previous rule excluded all node_modules files from the swc-loader. This adjustment to the excludes pattern allows for ts and tsx files.

Without this change (or an override to this rule's exclude field), webpack would emit this failing error:

You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.

Here is a workaround that I have been using on webpack.config which overrides that of the .config folder:

...
function isSwcLoaderRule(rule: any): rule is RuleSetRule {
  return rule?.use?.loader === 'swc-loader';
}
...


  // BEGIN FIX swc-loader to work with our internal git dependencies
  // Prevents error: "You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file."
  const swcLoaderRule = baseConfig.module?.rules?.filter(isSwcLoaderRule)[0];
  if (!swcLoaderRule) {
    throw new Error('Could not find the swc-loader rule. Has the .config/webpack.config.ts changed?');
  }
  // Exclude node_modules, except for typescript files (.ts, .tsx) possibly shared by git dependencies
  swcLoaderRule.exclude = /(node_modules)(?:(?!.*tsx?$))/;
  // END FIX

Having this exclude pattern within the boilerplate .config would be preferable to pasting this workaround in multiple projects webpack overrides.

@CLAassistant
Copy link

CLAassistant commented May 21, 2025

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

github-actions bot commented May 21, 2025

Hello! 👋 This repository uses Auto for releasing packages using PR labels.

✨ This PR can be merged but will not trigger a new release. To trigger a new release add the release label before merging.
NOTE: When merging a PR with the release label please avoid merging another PR. For further information see here.

@darrenjaneczek darrenjaneczek added the minor Increment the minor version when merged label May 21, 2025
@tolzhabayev tolzhabayev requested review from jackw and hugohaggmark and removed request for andresmgot, oshirohugo, s4kh and Ukochka May 26, 2025 09:54
Copy link
Collaborator

@jackw jackw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels very specific to a single use case to me. Gonna discuss it further in our slack channel first.

@github-project-automation github-project-automation bot moved this from 📬 Triage to 🧑‍💻 In development in Plugins Platform / Grafana Community May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Increment the minor version when merged
Projects
Status: 🧑‍💻 In development
Development

Successfully merging this pull request may close these issues.

3 participants