Cannot resolve built-in Node's "crypto" library
I have put "use node" directive in utils.ts. still no effect.
What am i doing wrong here?
5 Replies
i tried to put "platform: 'node'" instead of "use node"... still no use
Try to remove “use node” and the import line. We have a browser like
crypto
global.
See https://docs.convex.dev/functions/runtimes#web-crypto-apisRuntimes | Convex Developer Hub
Convex functions can run in two runtimes:
I would migrate to that browser like crpyto global, but there will to much code to change. So i decided to stick to node's crypto
This trick worked for me:-
take out all the logics that use node's crypto as utility function into a separate file. doesn't matter if you have written the crypto module's import statement or not, if you have used those utility function in some other file, you have to put "use node"; directive
this works only for Actions.
this wont work for Query or Mutation because only Actions can use Node.js runtime and query mutation cant
Example:- (Just to show a working demo code): https://github.com/ashuvssut/cookied/tree/dev/apps/convex
GitHub
cookied/apps/convex at dev · ashuvssut/cookied
Contribute to ashuvssut/cookied development by creating an account on GitHub.
i see this error as well when i have a file that imports convex-test