Skip to content
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

fix(scanner): catch all external files for glob imports #15286

Merged
merged 2 commits into from
Dec 14, 2023

Conversation

XiSenao
Copy link
Collaborator

@XiSenao XiSenao commented Dec 7, 2023

Description

fixes #15281
fixes #15284
refs #15140

Starting from esbuild@0.19.0, it will attempt to bundle glob imports modules, and the special point in handling glob import modules is to skip calling the onResolve hook and directly call the onLoad hook. If the module cannot be captured by the existing onLoad hook, then it will prompt "No loader is configured for ".xxx” files:", which is a common issue encountered in vite@5.0.0 and later versions.

Due to the inability of esbuild to call onResolve plugin when parsing glob imports, vite relies on esbuild during the initial pre-build phase to quickly scan the pre-built dependencies. The modification of #15140 only supports the suffixes supported by Vite. There is no additional processing for suffixes not supported by Vite, so import unsupported suffix types during the pre-build phase will result in an error when scanning dependencies. This change will handle all unconsidered suffixes as a fallback, preventing vite from throwing errors when scanning new suffixes during the pre-build phase.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines, especially the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Update the corresponding documentation if needed.
  • Ideally, include relevant tests that fail without this PR but pass with it.

Copy link

stackblitz bot commented Dec 7, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@sapphi-red sapphi-red added p2-edge-case Bug, but has workaround or limited in scope (priority) regression The issue only appears after a new release feat: deps optimizer Esbuild Dependencies Optimization labels Dec 9, 2023
@sapphi-red
Copy link
Member

I wonder if we should revert #15140 and just add the following code at the end? What do you think?

// onResolve is not called for glob imports.
// we need to add that here as well until esbuild calls onResolve for glob imports.
// https://github.com/evanw/esbuild/issues/3317
build.onLoad({ filter: '.', namespace: 'file' }, () => {
  const externalOnLoadResult: OnLoadResult = {
    loader: 'js',
    contents: 'export default {}',
  }
  return externalOnLoadResult
})

@XiSenao XiSenao force-pushed the fix/catch-all-external-files branch 2 times, most recently from 66e16c1 to 28a57cb Compare December 9, 2023 11:43
@XiSenao
Copy link
Collaborator Author

XiSenao commented Dec 9, 2023

In the setupExternalize function in #15140, I think it can be kept to serve as a functional prompt. I think that placing the build.onLoad hook contained within it at the end for fallback processing would suffice. Do you think so? @sapphi-red

@XiSenao
Copy link
Collaborator Author

XiSenao commented Dec 11, 2023

It seems that the test has returned to normal 🤔

@sapphi-red sapphi-red changed the title fix: catch all external files fix(scanner): catch all external files for glob imports Dec 12, 2023
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@XiSenao
Copy link
Collaborator Author

XiSenao commented Dec 14, 2023

What else needs to be considered for the current changes? @patak-dev

@patak-dev
Copy link
Member

Thanks for all your work in Vite lately @XiSenao!

@patak-dev patak-dev merged commit 129d0d0 into vitejs:main Dec 14, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: deps optimizer Esbuild Dependencies Optimization p2-edge-case Bug, but has workaround or limited in scope (priority) regression The issue only appears after a new release
Projects
None yet
3 participants