error TS2554: Expected 2 arguments, but got 3.
After migrating from 0.16.0 to 0.17.0, and I run "wasp start", it loads fine, but crashes with the errors
src/routes/apis/index.ts(436,59): error TS2554: Expected 2 arguments, but got 3.
[ Server ] src/routes/apis/index.ts(454,58): error TS2554: Expected 2 arguments, but got 3.
I can't pinpoint the source because that path src/routes/apis/index.ts doesn't exist - I'm guessing it's a runtime path that's generated in the output. How do I troubleshoot it to get to the exact source?
3 Replies
Hi @Kynetix. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
You're correct that the path src/routes/apis/index.ts is a generated file and doesn't exist in your source code—it's created by Wasp during the build process. This can make it difficult to trace errors like TS2554 ("Expected 2 arguments, but got 3") back to your own code.
This is a known pain point in Wasp: error messages from generated code often don't clearly indicate the original source of the problem. The Wasp team is aware of this and is working on improving error messages and source mapping to make debugging easier in the future. For now, here are some steps you can take to troubleshoot:
1. Check for Breaking Changes in the Upgrade
Since you upgraded from 0.16.0 to 0.17.0, it's possible that the API for certain functions (such as those used in your API namespace or middleware) changed, and your code is still using the old signature. Review the Wasp changelog or migration guide for 0.17.0 to see if any function signatures changed. 2. Look for Incorrect Imports or Function Usages
The error is likely caused by a function in your Wasp code (possibly in an apiNamespace or similar) being called with the wrong number of arguments. For example, if you have something like: and the imported function's signature changed, this could cause the error. 3. Check Your Wasp Declarations and Ext Imports
The error message is similar to those reported when an incorrect path or export is used in Wasp's import statements, or when the imported function's signature doesn't match what Wasp expects. Double-check your .wasp file and any imported JS/TS files for mismatches. 4. Generated Code Location
The generated file src/routes/apis/index.ts is located in the .wasp/out/server directory. You can open this file after running wasp build or wasp start to see the generated code and the exact line where the error occurs. This can help you trace back to which Wasp declaration or import is responsible. 5. Improving Error Messages
The Wasp team is actively working on making these errors more meaningful and easier to trace back to user code, including better source mapping and compile-time checks for incorrect imports or function signatures. For now, manual inspection is necessary, but improvements are on the way (Improve error messages reported by the framework code, Make errors more meaningful (source mapping)). Summary:
- Open .wasp/out/server/src/routes/apis/index.ts and check the lines mentioned in the error. - Trace which Wasp declaration or import is responsible for the generated code at those lines. - Check for any breaking changes in function signatures between 0.16.0 and 0.17.0. - Double-check your .wasp file and imported JS/TS files for mismatches. Unfortunately, until error reporting is improved, this manual process is necessary. If you continue to have trouble, consider sharing your Wasp file or relevant imports with the Wasp community for more targeted help. References:
- Improve error messages reported by the framework code - Make errors more meaningful (source mapping) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kynetix, 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?
Since you upgraded from 0.16.0 to 0.17.0, it's possible that the API for certain functions (such as those used in your API namespace or middleware) changed, and your code is still using the old signature. Review the Wasp changelog or migration guide for 0.17.0 to see if any function signatures changed. 2. Look for Incorrect Imports or Function Usages
The error is likely caused by a function in your Wasp code (possibly in an apiNamespace or similar) being called with the wrong number of arguments. For example, if you have something like: and the imported function's signature changed, this could cause the error. 3. Check Your Wasp Declarations and Ext Imports
The error message is similar to those reported when an incorrect path or export is used in Wasp's import statements, or when the imported function's signature doesn't match what Wasp expects. Double-check your .wasp file and any imported JS/TS files for mismatches. 4. Generated Code Location
The generated file src/routes/apis/index.ts is located in the .wasp/out/server directory. You can open this file after running wasp build or wasp start to see the generated code and the exact line where the error occurs. This can help you trace back to which Wasp declaration or import is responsible. 5. Improving Error Messages
The Wasp team is actively working on making these errors more meaningful and easier to trace back to user code, including better source mapping and compile-time checks for incorrect imports or function signatures. For now, manual inspection is necessary, but improvements are on the way (Improve error messages reported by the framework code, Make errors more meaningful (source mapping)). Summary:
- Open .wasp/out/server/src/routes/apis/index.ts and check the lines mentioned in the error. - Trace which Wasp declaration or import is responsible for the generated code at those lines. - Check for any breaking changes in function signatures between 0.16.0 and 0.17.0. - Double-check your .wasp file and imported JS/TS files for mismatches. Unfortunately, until error reporting is improved, this manual process is necessary. If you continue to have trouble, consider sharing your Wasp file or relevant imports with the Wasp community for more targeted help. References:
- Improve error messages reported by the framework code - Make errors more meaningful (source mapping) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kynetix, 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?
@kapa.ai I found the issue.
I have this api function
export const getConnectedAccountEarnings = async (req: Request, res: Response) {}
The generated code is
const getConnectedAccountEarningsMiddleware = globalMiddlewareConfigForExpress(_waspgetConnectedAccountEarningsmiddlewareConfigFn)
router.get(
'/api/connected-account-earnings/:connectedAccountId',
getConnectedAccountEarningsMiddleware,
defineHandler(
(
req: Parameters<typeof _waspgetConnectedAccountEarningsfn>[0],
res: Parameters<typeof _waspgetConnectedAccountEarningsfn>[1],
) => {
const context = {
entities: {
},
}
return _waspgetConnectedAccountEarningsfn(req, res, context)
}
)
)
The error occurs on this line
return _waspgetConnectedAccountEarningsfn(req, res, context)
where it expects 2 arguments but got 3. I'm guessing it doesn't like the 'context' parameter. But how do I eliminate it from the generated code so as to avoid teh error?
This is its current declaration in main.wasp
api getConnectedAccountEarnings {
fn: import { getConnectedAccountEarnings } from "@src/zigozi/apis",
auth: false,
httpRoute: (GET, "/api/connected-account-earnings/:connectedAccountId")
}
Let me check the knowledge base for you again. One moment! :books:
----------------------
The error occurs because Wasp expects your API implementation to accept three arguments:
(req, res, context)
. In your code, you have:
But the generated code calls it with three arguments:
To fix this, update your function signature to accept the third argument, context
, even if you don't use it:
This matches what Wasp expects for API implementations, as described in the documentation:
After you defined the API, it should be implemented as a NodeJS function that takes three arguments:You do not need to (and cannot) change the generated code—just update your function to accept the third argument. This will resolve the TS2554 error. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kynetix, 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?
1.req
: Express Request object
2.res
: Express Response object
3.context
: An additional context object injected into the API by Wasp
Docs: Defining the API's NodeJS Implementation