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

ESM subpath imports fail to be resolved by vite:import-analysis #12370

Closed
7 tasks done
tsujp opened this issue Mar 11, 2023 · 1 comment · Fixed by #12373
Closed
7 tasks done

ESM subpath imports fail to be resolved by vite:import-analysis #12370

tsujp opened this issue Mar 11, 2023 · 1 comment · Fixed by #12373

Comments

@tsujp
Copy link

tsujp commented Mar 11, 2023

Describe the bug

Directly related to this issue: #7770 which I have commented on also.

Looks like this has been included in Vite 4.2.0-beta.1. The changes to vite:resolve appear to work as it does resolve a subpath import correctly but it cannot be used with a real world codebase because import-analysis does not understand what to do with a subpath import when given it and so it resolves to null instead which returns:

PM [vite] Internal server error: Failed to resolve import "#src/routes/app_router" from "src/main.tsx". Does the file exist?
Plugin: vite:import-analysis
File: /path/to/codebase/apps/www/src/main.tsx:1:26
4  |  import { $$registry as _$$registry } from "solid-refresh";
5  |  const _REGISTRY = _$$registry();
6  |  import { AppRouter } from '#src/routes/app_router';
   |                             ^

Annotated with a bunch of console.log statements when trying to debug this I can see the following:

(1) asked to resolve: #src/routes/app_router
(2) problem is here: null
(3) asked to resolve: #src/routes/app_router resolved to: [ './src/routes/app_router.js' ]

(1) is from within vite:import-analysis right before it switches on if (!resolved).

console.log('asked to resolve:', url)
const resolved = await this.resolve(url, importerFile);
                if (!resolved) {

(2) is from within that if statement.

(3) is from within vite:resolve.

import-analysis calls some resolve method (I'm working with the post-bundled source here so there are umpteen definitions for that function) which doesn't know what to do hence the failure.

I'll try actually find this in the normal codebase before it's been bundled.

Minimum reproducible example here: https://stackblitz.com/edit/github-c6tkmr-1eubsp?file=src/index.tsx

Reproduction

https://stackblitz.com/edit/github-c6tkmr-1eubsp?file=src/index.tsx

Steps to reproduce

See above reproducible link.

System Info

Vite 4.2.0-beta.1
v18.13.0
Typescript 4.9.5
Firefox 109.0
macOS 12.4

Used Package Manager

pnpm

Logs

No response

Validations

@stackblitz
Copy link

stackblitz bot commented Mar 11, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@tsujp tsujp changed the title ESM subpath issues fail to be resolved by vite:import-analysis ESM subpath imports fail to be resolved by vite:import-analysis Mar 11, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant