W
Waspβ€’10mo ago
mindreaderlupoDO

import actions into main.wasp

I am struggling with the following problem: I defined an action in the actions.ts but I get the message that it is not exported. In the Browser I get the message that the import of actions.js failed. I am using the open saas template and I already tried to 'wasp clean' my project
No description
No description
No description
17 Replies
matijash
matijashβ€’10mo ago
can you try removing '.js' suffix, so only '@src/server/actions'?
mindreaderlupoDO
mindreaderlupoDOOPβ€’10mo ago
I tried it with out and with .ts both result in the same issue
MEE6
MEE6β€’10mo ago
Wohooo @mindreaderlupoDO, you just became a Waspeteer level 1!
martinsos
martinsosβ€’10mo ago
Hm this is quite weird @mindreaderlupoDO ! Just to be safe, try doing wasp clean and see if that helps. Also, let us know the result of wasp version -> I am assuming it is 0.12.something . Now, I see that in main.waps file, Wasp claims that you didn't export createProject from src/server/actions.js . It does like like you did though, in that actions.ts file. Two things I can see as an issue: 1. Maybe you don't have wasp start running, so it didn't build the .js file from .ts file? 2. Maybe that actions.ts file is not in src/server/ but somewhere else? What is even weirder is that Vite error you are getting. Vite is here for frontend, but here it is complaining about server files -> I guess it is importing their types? @miho might this be connected with the change you recently did with mangling the names a bit, because I see the _ext suffix on some names? Or are we just seeing them here but it is not connected with that? @mindreaderlupoDO can you get the code into shape where it worked, and then isolate the changes that made it stop work, and tell us exactly what those changes are?
miho
mihoβ€’10mo ago
What is even weirder is that Vite error you are getting. Vite is here for frontend, but here it is complaining about server files -> I guess it is importing their types? @miho might this be connected with the change you recently did with mangling the names a bit, because I see the _ext suffix on some names? Or are we just seeing them here but it is not connected with that?
We didn't merge the mangling yet πŸ˜„
martinsos
martinsosβ€’10mo ago
I know, but you mentioned the latest mangling is similar to sometihng you also did before (or somebody else did it before), so I assumed this _ext is that "before"? Was I wrong? In any case, have any idea @miho what could be the issue here? Notice that Vite is complaining although server file seems to be missing -> I guess because it is trying to import types from it?
miho
mihoβ€’10mo ago
Yep, _ext mangling was done before and by @Filip to keep our operation imports working πŸ˜„ Vite complains I guess because the resolution of imports failed for some reason. But, this means that some client code is importing something server related from the SDK (my guess)@mindreaderlupoDO did you import stuff from wasp/server/* anywhere in your client code?
mindreaderlupoDO
mindreaderlupoDOOPβ€’10mo ago
Thanks for your support. At the moment I don't have the time to go back to the project. Hopefully during the weekend I will try to elaborate on this issue and answer your questions Okay, looks like I made mistakes in the implementation, I was on the wrong path due to the types of error messages I got. But still I have trouble to understand whats happening. All the errors are related to the following: In my component, I have const newProject = createProject({id: 132,}); in Actions I have implemented it like this: export const createProject: CreateProject<Pick<Project, 'id'>, Project> = async ({ id }, context) => {...function definition...} Of course the problem is, that I only pass 1 property, "context" is missing. How do I do that? If I look at other implementations of actions in the Open SaaS Code, I see the same thing: E. g. DemoAppPage.tsx line 182: const response = await generateGptResponse({ hours: todaysHours, }); According to the definition in actions.ts line 102, there is also the property 'context': export const generateGptResponse: GenerateGptResponse<GptPayload, GeneratedSchedule> = async ({ hours }, context) => { ... } Sorry, might be very stupid but I am lost at this point. Thank you!
martinsos
martinsosβ€’10mo ago
@mindreaderlupoDO it's a good question -> so that context is sometihng that Wasp injects for you. Meaning you are doing it right by passing only { id: 132 }. context is created by Wasp and has stuff like user in it, and relevant Prisma entities like Project. My question would be, what was the very initial error you got, that made you try to fix this part and think you are doing somethign wrong? Btw have you checked our tutorial https://wasp-lang.dev/docs/tutorial/create ? It should give you a good introduction into how things work in Wasp, including stuff like context, it takes an hour or two to complete.
mindreaderlupoDO
mindreaderlupoDOOPβ€’10mo ago
Thanks, I walked through the tutorial but I was not able to figure out whats wrong in my case. The first screenshot attatched shows the code which causes the problem. Some of the other screenshots show the errors I got to make me think "context" causes the probem.
No description
No description
No description
No description
No description
No description
mindreaderlupoDO
mindreaderlupoDOOPβ€’10mo ago
I tried to hand over a fake second agrument: createProject({id: 123},' ') This makes the errors in the IDE and console disappear for the time being. However, the errors displayed in the browser remain:
[plugin:vite:import-analysis] Failed to resolve import "wasp/ext-src/server/actions.js" from "../sdk/wasp/dist/server/operations/actions/index.js". Does the file exist?
So it actually seems to have more to do with the import of the function.
Filip
Filipβ€’10mo ago
Hm, how are you importing the createProject operation?
martinsos
martinsosβ€’10mo ago
Ah yes, this is probably it. Because it seems like you somehow bypassed the part of Wasp that injects the context, which means you likely imported createProject directly via its .js file, instead of importing it via wasp/client/operations: import { createProject } from 'wasp/client/operations'
mindreaderlupoDO
mindreaderlupoDOOPβ€’10mo ago
Sounds very logic, but this is not the issue. I have done it like that:
No description
mindreaderlupoDO
mindreaderlupoDOOPβ€’10mo ago
Oh, now I see, it needs to be wasp/client/operations .... its finally working... thanks for all your support. At the end it was my fault... but during this discussion I learned a lot. Thanks!
MEE6
MEE6β€’10mo ago
Wohooo @mindreaderlupoDO, you just became a Waspeteer level 2!
Filip
Filipβ€’10mo ago
No worries! It's an easy mistake to make
Want results from more Discord servers?
Add your server