I get an error when creating externally facing APIs.

api healthCheck { fn: import { healthCheck } from "@src/server/health", httpRoute: (GET, "/health")} When running the above api declaration on my main.wasp, it should create the API types when 'wasp start' is running. However, in the func the import type, i get the error that Module '"wasp/server/api"' has no exported member 'HealthCheck'.ts(2305) on the import type in my logical function. I'm not sure if this is a bug or if i'm doing types wrongly.
3 Replies
kapa.ai
kapa.ai2w ago
Hi @LuzzaMcGuzza. 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 knowledge sources, when you declare an API in Wasp like this:
api healthCheck {
fn: import { healthCheck } from "@src/server/health",
httpRoute: (GET, "/health")
}
api healthCheck {
fn: import { healthCheck } from "@src/server/health",
httpRoute: (GET, "/health")
}
Wasp should generate a corresponding type for your API handler, which you can import from wasp/server/api in your TypeScript implementation:
import { HealthCheck } from "wasp/server/api";

export const healthCheck: HealthCheck = (req, res, context) => {
// implementation
};
import { HealthCheck } from "wasp/server/api";

export const healthCheck: HealthCheck = (req, res, context) => {
// implementation
};
However, if you are seeing the error:
Module '"wasp/server/api"' has no exported member 'HealthCheck'.ts(2305)
Module '"wasp/server/api"' has no exported member 'HealthCheck'.ts(2305)
this typically means that the Wasp compiler did not generate the expected type. The most common reasons for this are: 1. Wasp compiler hasn't run or hasn't picked up the new API declaration.
Make sure you have run wasp start after adding or changing your API declaration. This step is necessary for Wasp to generate the types (source). 2. There is a typo or mismatch in the API name.
The generated type name is based on the API name in your main.wasp. For your example, the type should be HealthCheck (PascalCase of the API name). Double-check that the API name in your import matches exactly the name in your main.wasp (source). 3. The import path is incorrect or the file is not in the right place.
Ensure that your import path in main.wasp is correct and that the file exists and exports the function as expected (source). 4. Wasp or TypeScript build artifacts are stale or corrupted.
Sometimes, cleaning the build artifacts helps. Run wasp clean and then wasp start again (source). If you have checked all of the above and the problem persists, it could be a bug or an edge case in the Wasp compiler. In that case, please provide more details or consider opening an issue on the Wasp GitHub repository. Summary:
- Make sure wasp start is running after your changes. - Confirm the API name and type name match. - Clean and rebuild with wasp clean and wasp start. - Ensure your import paths and file exports are correct. If after these steps the type is still not generated, the knowledge sources do not provide further troubleshooting steps, and it may be a bug. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @LuzzaMcGuzza, 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?
LuzzaMcGuzza
LuzzaMcGuzzaOP2w ago
doing a wasp clean fixed the no exported member issue. but a new error came out: Cannot find module 'wasp/server/api' or its corresponding type declarations.ts(2307) Okay, fixed the issue. You need double quotes around "wasp/server/api"
toticozeni
toticozeni2w ago
That shouldn't cause the issue. Hm, most likely Typescript LSP didn't manage to catch on the new changes immediately. That can happen.

Did you find this page helpful?