You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Vite is attempting to load the directory directly instead of resolving to index.ts. This results in the error:
[vite:load-fallback] Could not load C:\Users\Vinicius\Documents\Projetos\folder\my-app\apps\web-extension\src\services\auth (imported by src/lib/axios.ts): EISDIR: illegal operation on a directory, read
Expected Behavior
When importing from an alias that points to a directory (e.g. "@/web-extension/services/auth"), Vite should automatically resolve to the index.ts file inside that directory. This behavior works for relative imports (e.g. ../services/auth), but fails when using our alias configuration.
Since the folder services/auth contains an index.ts, the expected behavior is for Vite to resolve it automatically. Instead, it fails with the EISDIR error shown above.
[vite:load-fallback] Could not load C:\Users\Vinicius\Documents\Projetos\folder\my-app\apps\web-extension\src\services\auth (imported by src/lib/axios.ts): EISDIR: illegal operation on a directory, read
Package Manager Version
9.15.3
Operating System
macOS
Linux
Windows
Other (Please specify)
Additional Information
When building our Vite-based application in our NX monorepo (specifically in our “web-extension” project), importing from an alias that points to a directory (which contains an index.ts) fails during build. Instead of automatically resolving to index.ts, Vite attempts to load the directory, causing the following error:
[vite:load-fallback] Could not load C:\Users\Vinicius\Documents\Projetos\folder\my-app\apps\web-extension\src\services\auth (imported by src/lib/axios.ts): EISDIR: illegal operation on a directory, read
This error occurs even though our tsconfig.base.json maps "@/web-extension/*" to "apps/web-extension/src/*", and relative imports (e.g. ../services/auth) work as expected. This suggests that when using aliases, the expected fallback to index.ts is not happening.
Workarounds Tried
Explicit Import: Importing using "@/web-extension/services/auth/index.ts" works but is not desirable.
Relative Imports: Using relative paths like ../services/auth works, but it breaks consistency in our monorepo.
Custom Plugin: We implemented a custom Vite plugin (indexResolverPlugin) that checks if the resolved module is a directory and appends index.ts or index.js. However, this doesn’t fully address the issue when using our alias in an NX context.
Changing Alias Resolution: Adjusting the alias to use process.cwd() instead of __dirname avoids duplication in some cases, but the issue with the EISDIR error persists for alias-based imports.
Proposed Solution / Request
We would like guidance or a fix so that Vite correctly resolves directory aliases to their corresponding index.ts (or index.js) file in an NX monorepo setup. The resolution should behave the same as with relative imports without requiring manual modification of each import statement.
Any help or suggestions on how to resolve this alias resolution issue in this specific context would be greatly appreciated.
The text was updated successfully, but these errors were encountered:
Current Behavior
Vite is attempting to load the directory directly instead of resolving to
index.ts
. This results in the error:Expected Behavior
When importing from an alias that points to a directory (e.g.
"@/web-extension/services/auth"
), Vite should automatically resolve to theindex.ts
file inside that directory. This behavior works for relative imports (e.g.../services/auth
), but fails when using our alias configuration.GitHub Repo
No response
Steps to Reproduce
Project Structure:
tsconfig.base.json:
Vite Configuration (vite.config.base.ts):
project.json
Usage in Code:
In
src/lib/axios.ts
, we import the module like so:Since the folder
services/auth
contains anindex.ts
, the expected behavior is for Vite to resolve it automatically. Instead, it fails with the EISDIR error shown above.Nx Report
Failure Logs
Package Manager Version
9.15.3
Operating System
Additional Information
When building our Vite-based application in our NX monorepo (specifically in our “web-extension” project), importing from an alias that points to a directory (which contains an
index.ts
) fails during build. Instead of automatically resolving toindex.ts
, Vite attempts to load the directory, causing the following error:This error occurs even though our
tsconfig.base.json
maps"@/web-extension/*"
to"apps/web-extension/src/*"
, and relative imports (e.g.../services/auth
) work as expected. This suggests that when using aliases, the expected fallback toindex.ts
is not happening.Workarounds Tried
"@/web-extension/services/auth/index.ts"
works but is not desirable.../services/auth
works, but it breaks consistency in our monorepo.index.ts
orindex.js
. However, this doesn’t fully address the issue when using our alias in an NX context.process.cwd()
instead of__dirname
avoids duplication in some cases, but the issue with the EISDIR error persists for alias-based imports.Proposed Solution / Request
We would like guidance or a fix so that Vite correctly resolves directory aliases to their corresponding
index.ts
(orindex.js
) file in an NX monorepo setup. The resolution should behave the same as with relative imports without requiring manual modification of each import statement.Any help or suggestions on how to resolve this alias resolution issue in this specific context would be greatly appreciated.
The text was updated successfully, but these errors were encountered: