W
Wasp-lang•5mo ago
ArjunSohur

Module '"wasp/server/operations"' has no exported member 'scrapeArticles'.

Hey, I'm been having some trouble trying to resolve this bug related to a custom action that I'm trying to implement. I'm using the open Saas framework. Here's the line that giving me touble: import { scrapeArticles } from 'wasp/server/operations'; with error "Module '"wasp/server/operations"' has no exported member 'scrapeArticles'." I get this in a compenent .tsx file. Naturally, it seems like an error with setting up the scrapeArticles actions. So going to my main.wasp, I have: action scrapeArticles { fn: import { scrapeArticles } from "@src/server/actions.js" entities: [] } the docs say @src/actions.js, but the directory I have here is correct for my app. and rounding it off, in my actions.ts, I write: export const scrapeArticles = async () => { try { const response = await axios.post('http://127.0.0.1:8000/scrape_news'); return response.data; } catch (error) { console.error('Error scraping articles:', error); throw error; } }; I've tried - changing the actions.js => actions.ts in the wasp.main file - import {scrapeArticles} in actions.ts as the docs might suggest - resetting the typescript in the file that I'm getting the error in This is my first time writing an action is wasp, so forgive me if the error is staring at me. My friend was able to implement a toy function in almost the exact same way, so I have no idea what's going on. Thanks!
8 Replies
kapa.ai
kapa.ai•5mo ago
Hi @ArjunSohur. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- It seems like you've done a good job setting up your custom action. However, the issue might be with how you're trying to import the scrapeArticles action in your component. In your component, you're trying to import the action directly from 'wasp/server/operations', but this is not the correct way to import actions for use on the client side. Instead, you should import your actions from 'wasp/client/operations'. So, in your component, you should change the import statement to:
import { scrapeArticles } from 'wasp/client/operations';
import { scrapeArticles } from 'wasp/client/operations';
This is because Wasp injects the context (which includes the Prisma client and the logged-in user, if any) into the actions, and this is done through the 'wasp/client/operations' module. I hope this helps! Let me know if you have any other questions. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @ArjunSohur, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
ArjunSohur
ArjunSohurOP•5mo ago
@kapa.ai Yeah that's a good catch, but didn't solve it unfortunately - it's given the same error but with "client" instead of "server"
kapa.ai
kapa.ai•5mo ago
Let me check the knowledge base for you. One moment! :books: Sorry @ArjunSohur, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
ArjunSohur
ArjunSohurOP•5mo ago
Nevermind, I just re-implemented it and it works now 😋
miho
miho•5mo ago
Could you maybe share what you did differently? Maybe you started wasp start?
ArjunSohur
ArjunSohurOP•4mo ago
I've run into a similar error other times, i.e. an operation not getting recognized in 'wasp/client/operations', and it's usually been solved by doing wasp start, so yeah, though I didn't know it at the time, I think that's what actually solved it.
MEE6
MEE6•4mo ago
Wohooo @ArjunSohur, you just became a Waspeteer level 1!
ArjunSohur
ArjunSohurOP•4mo ago
If I keep noticing this trend, I'll let you know
Want results from more Discord servers?
Add your server