Cannot resolve node packages even with "use node"
I have "use node" indicated in my actions file, and that is the only place in my entire code where I am using the Node APIs. However, I am getting these errors:
51 Replies
Upon more testing, it seems like the actions are indeed using the node APIs buffer and string_decoder correctly (as part of iconv-lite). But it still throws these errors every single time I save any file which is distracting me from other genuine errors
Follow up: very bad news, this fails on convex deploy so I cannot push this to prod
Are you importing this "use node" file from any non-use node files?
a file with "use node" can use node modules for any actions it exports
If I call the action from a non use node mutation does that count?
generateVocabCardsAction is from the use node file
That's fine, it's only importing that is a problem.
hmm
and are this iconv-lite imported in any other files?
only this file
it's not imported directly by this file but it is imported by another file that this file imports
"use node" causes that file to be bundled differently such that it can no longer declare mutations and queries and it can use node APIs like "string_decoder"
yes
but that file has nothing except 2 actions both of which use node APIs
so any file that does not have "use node" will cause thus error if it imports that library
hm that sounds fine then
yes
it's very strange but i am stuck now because i cant deploy
hm, I'd try removing files from the convex directly to see which one is causing this issue (assuming there's no indication of which file was being bundled when this error occurs)
i know exactly which file
which i remove the one that uses iconv-lite the errors stop
One of the convex files that doesn't use "use node" is causing it
nope
it's this file specifically
or "use node" isn't working
when the imported file stops importing iconv-lite the error immediately goes away
what does the top of that file look like?
the "use node" part
"@/lib/functions/openai/vocab" uses iconv-lite (because openai has a bug now where they return non utf8 strings as utf8 so we need to manually decode)
huh could you double check that "vocab" isn't being imported from somewhere else?
confirm
Not openai/vocab, this file generation/vocab
it might be "./vocab", but looks like you always use the top level imports, nice
Would you be able to share this code? I'm tom@convex.dev, you could zip and email or share a GitHub repo with thomasballinger on GitHub
Sure
Let me send it to you now
@ballingt added you on GitHub
cloning to take a look
thank you
I think I see convex/server/meaning.ts --imports--> handle-duplicate-meanings.ts --imports--> "decode-openai" --imports--> iconv-lite
ah i see
i only imported the zod schemas
but seems like it might have traced the other imports too
hm yeah it doesn't seem to be able to tree-shake this
ok let me move the schemas to it's own file and try again
("it" == esbuild here the way it is invoked by convex)
also one more problem
zid() resolves to a string for some reason
not a big problem because i can override it but slightly annoying
Huh interesting, could you file that in https://github.com/get-convex/convex-helpers/issues
sure
thanks
ah I see, hm
my zid is the same one i copied from the convex helpers file
oh so it's the same code, but not actually the one imported from the library, got it — curious if it repros in the code. Ian recently has been packaging some of these up to make them importable
from convex/helpers right?
that package gives me super weird typescript errors when i install it
yup this one, i tried installing it and it started throwing weird typescript errors
it has some magic where it is able to throw typescript errors from node_modules even though it is ignored according to tsconfig
yeah that's it, cool it's under very active development so would be good to get a repro of that sometime
ok cool
will check it out again
I'm headed to bed, good luck + thanks for reporting these
thank you very much for saving my repo
have a good rest!
just an update: you are right, the latest implementation in convex-helpers does indeed fix the zid problem