Vinny
Vinny15mo ago

Consistently getting this error and not sure where to put platform: node

Hi, I'm currently a student hacker at Calhacks and I keep getting this error: [ERROR] Could not resolve "querystring" node_modules/centra/model/CentraRequest.js:4:19: 4 │ const qs = require('querystring') ╵ ~~~ The package "querystring" 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. ✘ [ERROR] Could not resolve "zlib" node_modules/centra/model/CentraRequest.js:5:21: 5 │ const zlib = require('zlib') ╵ ~~ The package "zlib" 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. ✘ [ERROR] Could not resolve "url" node_modules/centra/model/CentraRequest.js:6:22: 6 │ const {URL} = require('url') ╵ ~~~ This is my code: "use node"; import { v } from "convex/values"; import { action } from "./generated/server"; import { YoutubeTranscript } from 'youtube-transcript'; function mergeTextAndRemoveNewlines(data: any) { let mergedText = ''; for (let i = 0; i < data.length; i++) { const cleanedText = data[i].text.replace(/\n/g, '').trim(); mergedText += cleanedText + ' '; } return mergedText.trim(); } export const fetchTranscriptData = action({ args: { videoURL: v.string() }, handler: async (, args) => { { try { const transcriptData = await YoutubeTranscript.fetchTranscript(args.videoURL); const transcriptText = mergeTextAndRemoveNewlines(transcriptData); return transcriptText; } catch (error) { console.error('Error fetching transcript:', error); throw error; } } }, });
9 Replies
Vinny
VinnyOP15mo ago
I'm not really sure where to go from here
Wayne
Wayne15mo ago
@Vinny Hi, do you have a min, to stop by our booth to chat about your project at Cal Hacks?
erquhart
erquhart15mo ago
Are node built-ins supported in Convex’s node environment?
lee
lee15mo ago
Yes node built-ins are supported. This issue looks like you're importing the "centra" package (maybe transitively) from a convex file that does not start with "use node"
Wayne
Wayne15mo ago
@Vinny thanks for coming by the booth for help. We'll be here throughout the evening. Feel free to come back if you have any more questions.
Vinny
VinnyOP15mo ago
Thank you! Also, my output is what I expected:
No description
jeff
jeff10mo ago
Found another old issue I'm having! 😄 Also no resolution in thread :sad-duck-bill-emote-of-sorts:
jeff
jeff10mo ago
Okay, resolution for me (for posterity): I had a file, some_utils.ts that started with "use node"; and had an httpAction in there. (Illegal, as it turns out!) My http.ts included an export of this file, and itself did not start with "use node"; (which would be illegal; can't do that). The error messages all said:
The package "<such and such>" 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.
The package "<such and such>" 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.
Issue (my best guess): these packages were now being imported from http.ts which does not start with "use node";, therefore causing these issues. Solution: Define your httpAction in a non-node file, and make it call an internalAction with "use node";. From the docs:
HTTP actions run in the same environment as queries and mutations so also do not have access to Node.js-specific JavaScript APIs.
https://docs.convex.dev/functions/http-actions#limits
HTTP Actions | Convex Developer Hub
HTTP actions allow you to build an HTTP API right in Convex!
jeff
jeff10mo ago
✅ Resolved.

Did you find this page helpful?