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 support #269

Closed
dkzlv opened this issue Mar 31, 2021 · 3 comments
Closed

Vite support #269

dkzlv opened this issue Mar 31, 2021 · 3 comments

Comments

@dkzlv
Copy link

dkzlv commented Mar 31, 2021

I use Svelte Kit, it uses Vite. And I have problems with nanoid, because index.browser.js has checks on crypto being available on global namespace.

Even though the library's functions are not called during SSR, the module still gets imported in the Node. So this is what you would get in the new default Svelte Kit project if you just import nanoid in a component and do nothing with it:

11:17:09 AM [vite] Error when evaluating SSR module /node_modules/nanoid/index.dev.js:
Error: Your browser does not have secure random generator. If you don’t need unpredictable IDs, you can use nanoid/non-secure.
    at /node_modules/nanoid/index.dev.js:28:11
    at instantiateModule (../node_modules/vite/dist/node/chunks/dep-0776dd57.js:68919:166) (x163)

I propose to move the check inside the functions.

@TrySound
Copy link

SSR should use node version https://github.com/ai/nanoid/blob/main/index.js. Might be a bug in sveltekit.

@ai
Copy link
Owner

ai commented Mar 31, 2021

We have explicit instructions in package.json → exports that only browser should use index.browser.js.

Adding a browser check-in function will bloat the library multiple times.

Seems like Vite has an issue with SSR. Can you create an issue there?

@ai ai changed the title Move browser check inside the functions Vite support Mar 31, 2021
@ai
Copy link
Owner

ai commented Jun 8, 2021

I tested nanoid in fresh Vite and everything is working correctly

@ai ai closed this as completed Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants