Convex Action build error: could not resolve 'crypto-js'
I tried to
import CryptoJS from "crypto-js";
in a custom convex action
But on npx convex dev
I got this error (which I think comes from esbuild but I am not familiar with what is happening underlying Convex)
How can I mark this dep as external in my next.js project? I have installed the package from npm install.
Thanks for helping!6 Replies
Is this what you're looking for? https://docs.convex.dev/functions/bundling#external-packages
Putting
in
convex.json
at the root of your project?Bundling | Convex Developer Hub
Bundling is the process of gathering, optimizing and transpiling the JS/TS
btw there's a built-in
crypto
library in the node environment. See these threads:
https://discord.com/channels/1019350475847499849/1150837315229454388
https://discord.com/channels/1019350475847499849/1156511815212220426Hi @ian this is helpful thanks you! However I don't have a
Additional thoughts:
1. Thanks for this pointer and part of my bad that I never checked this bundling tutorial on docs site. I was checking the "Actions" tab to find solutions. Maybe if possible we can add a link from "Actions" page to the "Bundling" page
2. Regarding web crypto API on default runtime, good suggestion though. I tried AES-GCM there and got a Not Implemented error. Therefore I tried to use node runtime instead. Also using a npm pkg is easier for me to implement the encryption.
Hi sorry about this I figured out that after the external pkg fix it should work. The way I was importing "crypto-js" was wrong. This is resolved. And for the addition thoughts I think it should be still useful to share.
convex.json
file and I tried to create it manually in my next.js project. I tried both to create it under root folder or the ./convex/
folder. But I am still getting the same error (Could not resolve "crypto-js" You can mark the path "crypto-js" as external to exclude it from the bundle, which will remove
this error.).
My convex.json
Thank you for following up! What did the correct code look like in the end? Sorry it was hard to figure out- good idea to link to bundling. Any other ideas for improvements?
What if the crypto was installed in your dotenv package, and the attached is what you get, how do I resolve this?

You shouldn't use dotenv from convex packages, it's a Node.js library. What are you trying to use it for?