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

Broken in Vite 5 #129

Closed
tervay opened this issue Dec 10, 2023 · 9 comments
Closed

Broken in Vite 5 #129

tervay opened this issue Dec 10, 2023 · 9 comments
Labels
upstream bug Bug caused by a dependency

Comments

@tervay
Copy link

tervay commented Dec 10, 2023

https://stackblitz.com/edit/vitejs-vite-2pijh9?file=package.json

This stackblitz resembles a project structure I'm using that no longer works with Vite 5. In Vite 4, this project will (intentionally, in this Stackblitz case) fail due to a top-level await not being allowed in the configured environment (which is fine, expected, and desired in this case).

With Vite 5.0.2, this fails with the following stack trace:

❯ yarn build
yarn run v1.22.19
$ tsc && vite build
vite v5.0.2 building for production...
✓ 20 modules transformed.
[vite:worker] Cannot read properties of undefined (reading '/home/projects/vitejs-vite-2pijh9/src')
file: /home/projects/vitejs-vite-2pijh9/src/worker.ts?worker
error during build:
TypeError: Cannot read properties of undefined (reading '/home/projects/vitejs-vite-2pijh9/src')
    at Object.resolveId (file:///home/projects/vitejs-vite-2pijh9/node_modules/vite-tsconfig-paths/dist/index.mjs:175:45)
    at eval (file:///home/projects/vitejs-vite-2pijh9/node_modules/rollup/dist/es/shared/node-entry.js:18631:40)
    at async PluginDriver.hookFirstAndGetPlugin (file:///home/projects/vitejs-vite-2pijh9/node_modules/rollup/dist/es/shared/node-entry.js:18531:28)
    at async resolveId (file:///home/projects/vitejs-vite-2pijh9/node_modules/rollup/dist/es/shared/node-entry.js:17200:26)
    at async ModuleLoader.resolveId (file:///home/projects/vitejs-vite-2pijh9/node_modules/rollup/dist/es/shared/node-entry.js:17614:15)
    at async Object.resolveId (file:///home/projects/vitejs-vite-2pijh9/node_modules/vite/dist/node/chunks/dep-ErEj4WmL.js:8150:10)
    at async PluginDriver.hookFirstAndGetPlugin (file:///home/projects/vitejs-vite-2pijh9/node_modules/rollup/dist/es/shared/node-entry.js:18531:28)
    at async resolveId (file:///home/projects/vitejs-vite-2pijh9/node_modules/rollup/dist/es/shared/node-entry.js:17200:26)
    at async ModuleLoader.resolveId (file:///home/projects/vitejs-vite-2pijh9/node_modules/rollup/dist/es/shared/node-entry.js:17614:15)
    at async eval (file:///home/projects/vitejs-vite-2pijh9/node_modules/rollup/dist/es/shared/node-entry.js:17921:50)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I'm not familiar enough with Vite to further debug this.

@wangpin34

This comment was marked as spam.

@divmgl

This comment was marked as off-topic.

@dineug
Copy link

dineug commented Dec 23, 2023

vite-tsconfig-paths v3.6.0 downgrades will normal operation.

@aleclarson
Copy link
Owner

I could not reproduce with the given StackBlitz, @tervay. I also tried reproducing manually, but no luck. Please try clearing your node_modules, deleting your lockfile, and re-installing to see if that fixes it for you. Otherwise, please provide a proper reproduction, thanks.

@aleclarson aleclarson added the waiting for response The issue author needs to reply label Dec 24, 2023
@tervay
Copy link
Author

tervay commented Jan 1, 2024

@aleclarson The stackblitz will fail when running yarn build. I'm not sure how to make it run that by default instead of yarn run dev, but yarn build will fail.

@davbrito
Copy link

I'm having the same issue. It fails only when used as a worker plugin. Just like in the provided StackBlitz.

I could not reproduce with the given StackBlitz, @tervay. I also tried reproducing manually, but no luck. Please try clearing your node_modules, deleting your lockfile, and re-installing to see if that fixes it for you. Otherwise, please provide a proper reproduction, thanks.

The error only shows when you run the build command:
image

@davbrito
Copy link

The error happens at this line:

const resolvers = resolversByDir[projectDir]

My insight on this is that resolveId is being called before configResolved, or configResolved is not being called at all on the worker plugin. That way this line is not executed

resolversByDir = {}
and it ends up in the error since it's undefined.


I was able to workaround it by passing the same plugin object to both arrays, since it uses the same tsconfig for workers and main project. That way the resolversByDir gets prepopulated on the configResolved of the main plugin.

const tspaths = tsconfigPaths()

export default defineConfig({
  plugins: [tspaths],
  worker { plugins: () => [tspaths] },
})

@aleclarson
Copy link
Owner

This is a bug in Vite. I've opened this PR to fix it. Thanks for investigating, @davbrito. Neither of your suspicions were correct, but it helped save me some time. 👍

@aleclarson
Copy link
Owner

Closing this. The Vite PR has been merged. Not sure what the release schedule is these days. If you have any other problems with Vite 5 and this plugin, open a new issue.

@aleclarson aleclarson added upstream bug Bug caused by a dependency and removed waiting for response The issue author needs to reply labels Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream bug Bug caused by a dependency
Projects
None yet
Development

No branches or pull requests

6 participants