api error
im getting an error here with the api [ Server!] [!] RollupError: Could not resolve "../../../../../../src/payment/orders" from "src/routes/apis/index.ts"
[ Server!] src/routes/apis/index.ts
[ Server!] at getRollupError (/home/guinness/PetAll/.wasp/out/server/node_modules/rollup/dist/shared/parseAst.js:285:41)
[ Server!] at Object.error (/home/guinness/PetAll/.wasp/out/server/node_modules/rollup/dist/shared/parseAst.js:281:42)
[ Server!] at ModuleLoader.handleInvalidResolvedId (/home/guinness/PetAll/.wasp/out/server/node_modules/rollup/dist/shared/rollup.js:22762:36)
[ Server!] at /home/guinness/PetAll/.wasp/out/server/node_modules/rollup/dist/shared/rollup.js:22722:26
[ Server!] whats causing this?
11 Replies
Hi @Bruno Njeru. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
This usually means the path or export in your api declaration is wrong. Wasp compiles your api imports into server code (src/routes/apis/index.ts). If the ExtImport path doesn’t exist or doesn’t export the named symbol, Rollup can’t resolve it and throws this error. Verify in main.wasp that your api fn/middlewareConfigFn import points to an existing file under src with the correct relative alias (@src/…), and that the file actually exports the symbol you reference. For example:
Make sure:
- the file exists at src/payment/orders.ts (or .js) and
- it exports orders.
This class of error is known to surface as “Cannot find module … or has no exported member …” when the path/export is off, and improving these messages is an open issue. The fix is to correct the path and/or export in main.wasp (see examples and notes on api imports) (Custom HTTP API Endpoints). Similar path/export mistakes are tracked as confusing server build errors, e.g., missing file or missing export causing resolution errors (Improve error messages).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Bruno Njeru, 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?
the file is there and the api is exported @kapa.ai
Let me check the knowledge base for you again. One moment! :books:
----------------------
A few common gotchas to double‑check:
- Use the @src alias in main.wasp, not a relative filesystem path. Example:
Don’t point to ../../../../src/payment/orders in main.wasp; Wasp rewrites @src to the correct server path during build (Custom HTTP API Endpoints).
- Ensure the symbol name matches exactly. If main.wasp says import { orders }, the file must have export const orders = … or export function orders … (Improve error messages).
- Include a resolvable extension if needed. Some server imports without .js can fail and produce module-not-found errors; adding the .ts/.js can help in certain setups (Improve error messages).
- Clean and rebuild to fix stale .wasp output:
This resolves cases where valid files/exports still fail due to a broken .wasp cache (Missing wasp/* specifiers).
If it still fails, please paste:
- the api block from main.wasp,
- the exact export from src/payment/orders.(ts|js),
- your Wasp version,
so we can spot any subtle mismatch. (Examples and field reference: API Reference; known confusing resolution errors: issue).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Bruno Njeru, 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?
still getting the error after wasp clean @kapa.ai
Let me check the knowledge base for you again. One moment! :books:
----------------------
Thanks for checking with wasp clean. Next, please verify these specifics in your main.wasp and file:
1) Use @src in the api import, not a relative path:
If you’re using ../../../../src/payment/orders anywhere, switch to @src/payment/orders (API Reference).
2) Ensure the export name matches exactly:
- main.wasp: import { orders }
- src/payment/orders.(ts|js): export const orders = … or export function orders …
If the file exists but the named export is off, Wasp surfaces a confusing server build error (tracked as an issue) (Improve error messages). 3) Try adding/removing the extension in main.wasp: - Some server imports without .js can fail; adding .js (or .ts) can resolve resolution quirks, and missing extensions have been reported to cause ERR_MODULE_NOT_FOUND-like errors (Issue context, related discussion). 4) Confirm the file is under src (not outside), e.g., src/payment/orders.(ts|js). The Wasp docs/examples assume imports resolve from @src/* (Custom HTTP API Endpoints). If it still fails, please paste: - the api block from main.wasp, - the export snippet from src/payment/orders.(ts|js), - your Wasp version. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Bruno Njeru, 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?
If the file exists but the named export is off, Wasp surfaces a confusing server build error (tracked as an issue) (Improve error messages). 3) Try adding/removing the extension in main.wasp: - Some server imports without .js can fail; adding .js (or .ts) can resolve resolution quirks, and missing extensions have been reported to cause ERR_MODULE_NOT_FOUND-like errors (Issue context, related discussion). 4) Confirm the file is under src (not outside), e.g., src/payment/orders.(ts|js). The Wasp docs/examples assume imports resolve from @src/* (Custom HTTP API Endpoints). If it still fails, please paste: - the api block from main.wasp, - the export snippet from src/payment/orders.(ts|js), - your Wasp version. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Bruno Njeru, 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?
api orders {
fn: import { orders } from "@src/payment/api/orders/orders",
httpRoute: (POST, "/internal/orders"),
entities: [Order],
auth: false
} and
export const orders: Orders = async (req, res, context) => {
try { im using wasp version 16.2 @kapa.ai
Let me check the knowledge base for you again. One moment! :books:
----------------------
Thanks for the snippet. A few targeted checks given your setup:
- Confirm the import alias and path in main.wasp exactly matches the file:
- main.wasp: fn: import { orders } from "@src/payment/api/orders/orders"
- File exists at: src/payment/api/orders/orders.(ts|js)
- If your file name is index.(ts|js) inside orders/, change import to "@src/payment/api/orders/orders/index" or just "@src/payment/api/orders/orders" only if the file itself is named orders.(ts|js) (Wasp rewrites @src; don’t use relative ../../ paths) (see examples under API declaration) (Custom HTTP API Endpoints).
- Ensure the named export matches:
- In src/payment/api/orders/orders.ts: export const orders = ... or export function orders ...
- In TypeScript, you can also add the generated type: import { Orders } from "wasp/server/api"; then export const orders: Orders = (...) => { ... } (Defining the API's NodeJS Implementation).
- Try toggling the extension in main.wasp:
- If you currently have no extension, try adding .ts or .js; if you have one, try removing it. Missing extensions have been reported to produce module-not-found style errors in server builds (Improve error messages).
- Clean build artifacts again to rule out stale .wasp:
- wasp clean && wasp start (this fixes cases where valid files/exports still fail) (Missing wasp/* specifiers).
- Finally, confirm Order entity is declared and matches entities: [Order] so Wasp can inject it into context (the pattern mirrors how entities are added for APIs) (Using Entities in APIs).
If it still errors, please paste:
- the exact file path and name,
- whether it’s .ts or .js,
- the first lines of the file showing export const orders ...,
- the exact error after these changes.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Bruno Njeru, 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?
still getting the error even with the js/ts extension @kapa.ai the imports are ok according to the docs as well as the api def in main.wasp
Let me check the knowledge base for you again. One moment! :books:
----------------------
Understood. Given your setup looks correct, this error typically still comes from how the server import gets resolved after Wasp rewrites @src. Please try these focused checks:
- In main.wasp, keep using @src and ensure the file truly matches the path:
- fn: import { orders } from "@src/payment/api/orders/orders[.ts|.js]"
- File exists at src/payment/api/orders/orders.(ts|js), and it exports orders (export const orders …). This is the documented pattern for API imports (fn) and matches the examples (Custom HTTP API Endpoints; Using Entities in APIs).
- Avoid relative paths (../../…) in main.wasp. Wasp compiles your import into src/routes/apis/index.ts; if the path doesn’t map via @src, Rollup can’t resolve it and you’ll see exactly this kind of error (API Reference; similar confusion tracked here: Improve error messages).
- Open .wasp/out/server/src/routes/apis/index.ts and check the generated import that points to ../../../../../../src/payment/api/orders/orders(.js). If it’s missing the extension or points to a wrong path, adjust main.wasp to include the exact .js or .ts to align what Rollup expects (this mismatch is a known source of ERR_MODULE_NOT_FOUND/Rollup resolve errors) (Improve error messages; related import-extension inconsistencies discussion: Fix inconsistent import extensions).
- Do a clean rebuild:
- wasp clean
- wasp start
This fixes broken .wasp output that can cause “cannot find module” even when files are correct (Discord thread).
If after this the import in .wasp/out/server/src/routes/apis/index.ts still points to a non-existent path, please share:
- The exact generated import line from that file,
- Your main.wasp api block,
- The exact on-disk file path and name.
These details let us pinpoint whether it’s a path rewrite or extension resolution issue in the generated server code (a class of errors we’re tracking to improve messaging) (Improve error messages).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Bruno Njeru, 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?
i changed to node version 20 and it works @kapa.ai
Let me check the knowledge base for you again. One moment! :books:
----------------------
Great! That matches recent changes: since Wasp 0.12, Node.js >= 18 is supported, so Node 20 should work. There was a known issue with Node 20 due to a Web Crypto polyfill that’s been fixed by conditionally applying it, so upgrading can resolve build-time resolution issues you were seeing with the server bundle (Older node version still needed?, Web Crypto API polyfill breaks on Node 20, Improve CI to test supported Node versions).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Bruno Njeru, 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?