W
Wasp-lang•2mo ago
ArjunSohur

Trouble setting up a cron job

I'm trying to set up a cron job, but I'm getting an odd error message:
node:internal/errors:496
ErrorCaptureStackTrace(err);
^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/app/.wasp/out/sdk/wasp/dist/client/operations/actions' is not supported resolving ES modules imported from /app/.wasp/out/sdk/wasp/dist/client/operations/index.js
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at new NodeError (node:internal/errors:405:5)
at finalizeResolution (node:internal/modules/esm/resolve:320:17)
at moduleResolve (node:internal/modules/esm/resolve:946:10)
at defaultResolve (node:internal/modules/esm/resolve:1132:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36) {
code: 'ERR_UNSUPPORTED_DIR_IMPORT',
url: 'file:///app/.wasp/out/sdk/wasp/dist/client/operations/actions'
}

Node.js v18.18.0
npm notice
npm notice Run `npm install -g [email protected]` to update!
npm notice
exited with code 1
node:internal/errors:496
ErrorCaptureStackTrace(err);
^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/app/.wasp/out/sdk/wasp/dist/client/operations/actions' is not supported resolving ES modules imported from /app/.wasp/out/sdk/wasp/dist/client/operations/index.js
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at new NodeError (node:internal/errors:405:5)
at finalizeResolution (node:internal/modules/esm/resolve:320:17)
at moduleResolve (node:internal/modules/esm/resolve:946:10)
at defaultResolve (node:internal/modules/esm/resolve:1132:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36) {
code: 'ERR_UNSUPPORTED_DIR_IMPORT',
url: 'file:///app/.wasp/out/sdk/wasp/dist/client/operations/actions'
}

Node.js v18.18.0
npm notice
npm notice Run `npm install -g [email protected]` to update!
npm notice
exited with code 1
From a working version, all I did was: main.wasp:
job makeNewsletters {
executor: PgBoss,
perform: {
fn: import { doAll } from "@src/workers/bar"
},
// every 5 minutes for testing
schedule: {
cron: "5 * * * *",
},
entities: [User, Topic, Blurbs, Preferences, NewsArticles, Newsletter]
}
job makeNewsletters {
executor: PgBoss,
perform: {
fn: import { doAll } from "@src/workers/bar"
},
// every 5 minutes for testing
schedule: {
cron: "5 * * * *",
},
entities: [User, Topic, Blurbs, Preferences, NewsArticles, Newsletter]
}
src/workers/bar:
import { doEverything } from 'wasp/client/operations';
import { type MakeNewsletters } from 'wasp/server/jobs';

type Input = {}
type Output = { message: string }

export const doAll: MakeNewsletters<Input, Output> = async () => {
return doEverything(undefined)
import { doEverything } from 'wasp/client/operations';
import { type MakeNewsletters } from 'wasp/server/jobs';

type Input = {}
type Output = { message: string }

export const doAll: MakeNewsletters<Input, Output> = async () => {
return doEverything(undefined)
And in actions.ts:
import { makeNewsletters } from 'wasp/server/jobs'
const job = await makeNewsletters.submit({})
import { makeNewsletters } from 'wasp/server/jobs'
const job = await makeNewsletters.submit({})
17 Replies
kapa.ai
kapa.ai•2mo 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: ---------------------- Based on the error message you provided, it seems like the issue is related to the import of the actions directory. The error message Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/app/.wasp/out/sdk/wasp/dist/client/operations/actions' is not supported resolving ES modules imported from /app/.wasp/out/sdk/wasp/dist/client/operations/index.js suggests that there might be a problem with how the actions are being imported or used. In your actions.ts file, you are trying to import makeNewsletters from 'wasp/server/jobs' and then calling makeNewsletters.submit({}). However, based on the information provided, it's not clear if makeNewsletters is correctly exported from 'wasp/server/jobs' or if the submit method is correctly defined. Also, it's worth noting that in your main.wasp file, you are importing doAll from "@src/workers/bar". Make sure that doAll is correctly exported from bar.js file. Here is an example of how to declare a job in Wasp:
job mySpecialJob {
executor: PgBoss,
perform: {
fn: import { foo } from "@src/workers/bar",
executorOptions: {
pgBoss: {=json { "retryLimit": 1 } json=}
}
},
schedule: {
cron: "*/5 * * * *",
args: {=json { "foo": "bar" } json=},
executorOptions: {
pgBoss: {=json { "retryLimit": 0 } json=}
}
},
entities: [Task],
}
job mySpecialJob {
executor: PgBoss,
perform: {
fn: import { foo } from "@src/workers/bar",
executorOptions: {
pgBoss: {=json { "retryLimit": 1 } json=}
}
},
schedule: {
cron: "*/5 * * * *",
args: {=json { "foo": "bar" } json=},
executorOptions: {
pgBoss: {=json { "retryLimit": 0 } json=}
}
},
entities: [Task],
}
(Source: Wasp Docs (https://wasp-lang.dev/docs/advanced/jobs#declaring-jobs)) If the issue persists, it might be helpful to seek support from the Wasp community or the Wasp team directly. They might be able to provide more specific guidance based on the exact configuration and code of your project. ---------------------- 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
ArjunSohur•2mo ago
@kapa.ai It's an odd error because this is the file that it's yelling at me about:
// PUBLIC API
export * from './actions'
// MOSTLY PUBLIC API (see the file for details)
export * from './queries'

export {
// PUBLIC API
useAction,
// PUBLIC API
useQuery,
// PUBLIC API
type OptimisticUpdateDefinition,
} from './hooks'

export {
// PUBLIC API
configureQueryClient,
// PRIVATE API (framework code)
initializeQueryClient,
// PRIVATE API (framework code)
queryClientInitialized
} from './queryClient'
// PUBLIC API
export * from './actions'
// MOSTLY PUBLIC API (see the file for details)
export * from './queries'

export {
// PUBLIC API
useAction,
// PUBLIC API
useQuery,
// PUBLIC API
type OptimisticUpdateDefinition,
} from './hooks'

export {
// PUBLIC API
configureQueryClient,
// PRIVATE API (framework code)
initializeQueryClient,
// PRIVATE API (framework code)
queryClientInitialized
} from './queryClient'
Which I can't detect any errors in. It's also odd that only when I put a job in wasp.main and make the workers/bar.ts does it complain.
kapa.ai
kapa.ai•2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- The error message you're seeing is related to ES Modules in Node.js. The error ERR_UNSUPPORTED_DIR_IMPORT is thrown when you're trying to import a directory instead of a specific module. In ES Modules, unlike in CommonJS, importing directories is not supported. In your code, you're exporting everything from the actions and queries directories:
export * from './actions'
export * from './queries'
export * from './actions'
export * from './queries'
This is likely what's causing the error. You should instead import specific modules from these directories. If you have an index.js (or index.ts for TypeScript) file in these directories that re-exports all the modules, you can import that instead. For example, if you have actions/index.js and queries/index.js, you can do:
export * from './actions/index'
export * from './queries/index'
export * from './actions/index'
export * from './queries/index'
This way, you're not importing the directories themselves, but the index.js files that re-export all the modules. If the issue persists, it might be helpful to seek support from the Wasp community or the Wasp team directly. They might be able to provide more specific guidance based on the exact configuration and code of your project. ---------------------- 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
ArjunSohur•2mo ago
@kapa.ai Since this is in .wasp, I have no control over the actual code itself since it rebuilds itself every time. And I've also tried wasp clean.
kapa.ai
kapa.ai•2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- I see, if the problematic code is in the .wasp directory, it's indeed generated by Wasp and not directly controllable. The issue you're experiencing seems to be related to the way Wasp handles file changes and rebuilds the application. There are some discussions and open issues in the Wasp community that indicate similar problems: - In a Discord thread (https://discord.com/channels/686873244791210014/1223304305206099969), users reported that the application reloads and rebuilds after every UI change, which can be disruptive and cause issues in certain scenarios. - An open issue on GitHub (https://github.com/wasp-lang/wasp/issues/1844) discusses the need to investigate how file watching and hot reloading work in Wasp, especially after the restructuring in Wasp 0.12.0. Unfortunately, based on the provided knowledge sources, there isn't a clear solution to your problem. It might be a bug or a limitation in the current version of Wasp. I recommend reaching out to the Wasp community or the Wasp team directly for further assistance. You can share the details of your issue, and they might be able to provide a workaround or fix. ---------------------- 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
ArjunSohur•2mo ago
yikes
miho
miho•2mo ago
Does src/workers/bar have an extension?
ArjunSohur
ArjunSohur•2mo ago
Yes, it's a .ts
ArjunSohur
ArjunSohur•2mo ago
Recurring Jobs | Wasp
In most web apps, users send requests to the server and receive responses with some data. When the server responds quickly, the app feels responsive and smooth.
miho
miho•5w ago
I see wasp/client/operations import on the server? That's not supported, it should be wasp/server/operations
ArjunSohur
ArjunSohur•5w ago
That's a good catch, but unfortunately it didn't fix it. Here's the error again, if it's any help:
wasp-server-1 | Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/.wasp/out/sdk/wasp/dist/ext-src/payment/plans' imported from /app/.wasp/out/sdk/wasp/dist/ext-src/payment/operations.js
wasp-server-1 | at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
...
wasp-server-1 | code: 'ERR_MODULE_NOT_FOUND'
wasp-server-1 | }
wasp-server-1 | Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/.wasp/out/sdk/wasp/dist/ext-src/payment/plans' imported from /app/.wasp/out/sdk/wasp/dist/ext-src/payment/operations.js
wasp-server-1 | at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
...
wasp-server-1 | code: 'ERR_MODULE_NOT_FOUND'
wasp-server-1 | }
I'm going to try resetting and doing it over again, though I've already done that. Ok, I've messed around a little and gotten a new error. This time, I'm not being over zealous and I'm just seeing if I can get a job of sorts running. In sendNewsletters.ts (premade file):
import {type MakeNewsletter } from 'wasp/server/jobs';

export const makeNewsLetters: MakeNewsletter<never, void> = async (args: any, context: any) => {
console.log("Job executed")
}
import {type MakeNewsletter } from 'wasp/server/jobs';

export const makeNewsLetters: MakeNewsletter<never, void> = async (args: any, context: any) => {
console.log("Job executed")
}
In main.wasp:
job makeNewsletter {
executor: PgBoss,
perform: {
fn: import { makeNewsLetters } from "@src/newsletter/sendNewsletter"
},
schedule: {
cron: "1 * * * *"
},
entities: [User, Topic, Blurbs, Preferences, NewsArticles, Newsletter]
}
job makeNewsletter {
executor: PgBoss,
perform: {
fn: import { makeNewsLetters } from "@src/newsletter/sendNewsletter"
},
schedule: {
cron: "1 * * * *"
},
entities: [User, Topic, Blurbs, Preferences, NewsArticles, Newsletter]
}
This complies, but when I add
const submittedJob = await makeNewsletter.submit({})
const submittedJob = await makeNewsletter.submit({})
in actions.ts, I get no error message, but the wasp docker container crashes: wasp-server-1 exited with code 13 @kapa.ai Maybe you can help here?
kapa.ai
kapa.ai•5w ago
Let me check the knowledge base for you. One moment! :books: ---------------------- The error you're encountering seems to be related to the way you're trying to submit the job in actions.ts. In Wasp, jobs are submitted using the submit method, which takes an argument that is passed to the job handler function. This argument should match the Input type of your job handler function. In your case, you've defined the Input type as never, which means it should never receive any arguments. However, you're trying to submit the job with an empty object {} as an argument, which could be causing the issue. Here's how you can submit a job in Wasp:
import { mySpecialJob } from 'wasp/server/jobs'

const submittedJob = await mySpecialJob.submit({ job: "Johnny" })
import { mySpecialJob } from 'wasp/server/jobs'

const submittedJob = await mySpecialJob.submit({ job: "Johnny" })
(Source: Wasp Docs (https://wasp-lang.dev/docs/advanced/jobs#javascript-api)) In your case, since you've defined the Input type as never, you should submit the job without any arguments:
const submittedJob = await makeNewsletter.submit()
const submittedJob = await makeNewsletter.submit()
If the issue persists, it might be helpful to seek support from the Wasp community or the Wasp team directly. They might be able to provide more specific guidance based on the exact configuration and code of your project. ---------------------- 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
ArjunSohur•5w ago
Yeah, sorry Kapa, that didn't work, wasp will complain if I don't pass anything into submit.
MEE6
MEE6•5w ago
Wohooo @ArjunSohur, you just became a Waspeteer level 3!
ArjunSohur
ArjunSohur•5w ago
So in general, I'm having trouble running the job rather than declaring the job
Filip
Filip•5w ago
Hey @ArjunSohur, can you maybe share the code that reproduces the error (an app in a zip file) so I can get into it as quickly as possible?
ArjunSohur
ArjunSohur•5w ago
@sodic So it turns out I didn't rtfm carefully enough... There was really never any problem, I just didn't understand how cron worked 🥲
Want results from more Discord servers?
Add your server