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

Vite bundles wrong file from Zod #2639

Closed
websocket98765 opened this issue Mar 22, 2021 · 5 comments
Closed

Vite bundles wrong file from Zod #2639

websocket98765 opened this issue Mar 22, 2021 · 5 comments

Comments

@websocket98765
Copy link

websocket98765 commented Mar 22, 2021

When importing Zod into a Svelte Kit project, Vite attempts to import a typescript file, for an unknown reason. The author of Zod confirmed this should not be happening, it should use Zod's JavaScript entry point.

Error

The error is ENOENT: no such file or directory, open '/Users/me/my-app/node_modules/zod/src/index.ts'. But Zod actually has a JavaScript entry point.

Zod was imported via: import * as z from 'zod';

Reproduce

To reproduce, create a svelte kit project

npm init svelte@next my-app
cd my-app
npm i
npm i zod

Then in index.svelte, add this import import * as z from 'zod';, and save. It should cause an error in the dev server console.

Info

Vite: ^2.1.0
@sveltejs/kit: next
zod: ^3.0.0-alpha.24
Node:  v14.7.0
NPM: 7.6.3
MacOS
@voboda
Copy link

voboda commented Mar 25, 2021

The same happens with @supabase/supabase-js, which also has a js entrypoint (in case it helps to know)

@benmccann
Copy link
Collaborator

Here's a link to the Supabase issue: supabase/supabase-js#89

@benmccann
Copy link
Collaborator

Does this work if you install it as a devDependency?

@websocket98765
Copy link
Author

websocket98765 commented Mar 30, 2021

Oh my, that worked! I thought I tried that, but I removed it and re-added it to be sure, and it worked:

npm remove zod
npm i -D zod

(Worth noting that I originally had it in dependencies because zod defines validation schemas to be used by both the client and the server. But for Svelte Kit at least, using zod in devDependencies still works on both client and server.)

@benmccann
Copy link
Collaborator

Should this issue be closed then?

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants