HelmetH
Convex Community3y ago
10 replies
Helmet

Error related to Node.js (package not found on filesystem)

Hey guys, I'm currently attempting to prototype a langchain-based retrieval QA system with user chat messages. Currently handling a user's query within action, in which I send the query string to a function from a separate file in the same convex directory to do the retrieval augmentation work (dir looks somewhat like convex/mainFunctions.ts and convex/retrievalQA.ts).

However, running the convex code is giving the following error:

[ERROR] Could not resolve "node:path"

    node_modules/langchain/dist/vectorstores/hnswlib.js:165:32:
      165 │       const path = await import("node:path");
          ╵                                 ~~~~~~~~~~~

  The package "node:path" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.


It's giving errors for other imports such as node:fs/promises as well. HNSWLib, a vectorstore that langchain provides a wrapper for, imports these node utilities, and from what my aggressive googling has informed me the issue has something to do with the environment in which Convex is running. Most of the googling shows Cloudflare or Sveltekit-related issues (ie https://stackoverflow.com/questions/73178856/sveltekit-packages-not-being-able-to-access-node-functions, https://github.com/evanw/esbuild/issues/1996, etc). I'm not really sure if Convex's run environment doesn't support node or isn't up-to-date past v18 (which introduced prefixed imports), or if even is related to Convex at all.

What I want: for those who have used external functions from other files, how do you recommend accomplishing something similar to what I am trying to do? Is it ok that I use functions from other files within the convex directory? Does Convex run node, and if so, what would be causing this issue? I've read that it might be related to polyfills, but not sure. Any and all help appreciated!!
Stack Overflow
I am building an app with SvelteKit and publishing it to Cloudflare Pages, but it is some packages I am using are not able to access node native functions. Here's the build log:
2022-07-30T19:05:14.
SvelteKit: Packages not being able to access node functions
GitHub
An extremely fast bundler for the web. Contribute to evanw/esbuild development by creating an account on GitHub.
Issues · evanw/esbuild
Was this page helpful?