ai / nanoid

A tiny (124 bytes), secure, URL-friendly, unique string ID generator for JavaScript
https://zelark.github.io/nano-id-cc/
MIT License
24.33k stars 788 forks source link

crypto is not defined #397

Closed wfs498121294 closed 1 year ago

wfs498121294 commented 1 year ago

Hello,I have a problem

vue2.0 js

WAServiceMainContext.js?t=wechat&s=1666572189672&v=2.27.0:1 ReferenceError: crypto is not defined at nanoid (index.browser.js:20) at VueComponent.tapService (mine.vue:136) at index.js?543d:1892 at Array.forEach () at index.js?543d:1847 at Array.forEach () at zo.handleEvent [as __e] (index.js?543d:1837) at Object.i.safeCallback (WASubContext.js?t=wechat&s=1666572189672&v=2.27.0:1) at WASubContext.js?t=wechat&s=1666572189672&v=2.27.0:1 at Cn (WASubContext.js?t=wechat&s=1666572189672&v=2.27.0:1)(env: macOS,mp,1.06.2209190; lib: 2.27.0) image

ai commented 1 year ago

Is it in browser or in Node.js?

georgezouq commented 1 year ago

I have same problem, in a rollup js component with nanoid used in create-react-app, browser @ai

ai commented 1 year ago

@georgezouq do you have this issue in browser or when you run tests in Node.js?

wfs498121294 commented 1 year ago

Is it in browser or in Node.js?

wx miniprogram in Node.js

ai commented 1 year ago

@wfs498121294 you should add Web Crypto polyfill or avoid using bundler for Node.js

wfs498121294 commented 1 year ago

@wfs498121294 you should add Web Crypto polyfill or avoid using bundler for Node.js

thanks,I am puzzled,I'm a rookie,I do not know how to solve it.

wfs498121294 commented 1 year ago

Is it in browser or in Node.js?

thanks,I am puzzled,I'm a rookie,I do not know how to solve it.

hanjinye commented 4 months ago

I got the same issue in wechat mini-program development, I solved it the with import { nanoid } from 'nanoid/non-secure'. pls have a try with this, good luck.