Property does not exist on type
I'm missing something adding new vars in 0.16.2?
(was already declared in the template)
const openaiApi = new openai.OpenAI({
apiKey: env.OPENAI_API_KEY,
});
(added)
const deepseekApi = new openai.OpenAI({
apiKey: env.DEEPSEEK_API_KEY,
});
error TS2339: Property 'DEEPSEEK_API_KEY' does not exist on type '{ NODE_ENV: "development"; WASP_SERVER_URL: string; WASP_WEB_CLIENT_URL: string; JWT_SECRET: string; OPENAI_API_KEY: string; PORT: number; DATABASE_URL: string; SKIP_EMAIL_VERIFICATION_IN_DEV: boolean; GOOGLE_CLIENT_ID: string; GOOGLE_CLIENT_SECRET: string; PG_BOSS_NEW_OPTIONS?: string | undefined; } | { ...; }'
6 Replies
Hi @NEROX. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
It looks like you're encountering a TypeScript error when trying to add a new environment variable (
DEEPSEEK_API_KEY
) to your Wasp project. This error occurs because TypeScript doesn't recognize your new environment variable.
How to Fix This Issue
In Wasp, you need to define environment variables in two places:
1. In your .env.server
file (for development):
2. In production, you'll need to set this environment variable according to your deployment platform.
However, the TypeScript error suggests that Wasp's type definitions for environment variables don't include your new variable. This is because Wasp has a predefined set of environment variables it recognizes by default.
Current Environment Variable System
Wasp currently doesn't have a built-in way to define custom environment variable types using Zod or similar validation libraries, although this is being considered for future implementation.
Workaround Solution
You can use a type assertion to work around this TypeScript error:
This tells TypeScript to treat process.env.DEEPSEEK_API_KEY
as a string, bypassing the type checking.
Alternatively, if you're using the env
object that's provided by Wasp, you can use:
Remember to add the actual environment variable to your .env.server
file for development and set it appropriately in your production environment.
For more information about environment variables in Wasp, you can check the official documentation on environment variables.
I hope this helps resolve your issue!
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @NEROX, 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?✅ Fixed adding them to Zod (src/env.ts)
Perfect!
@kapa.ai
wasp 0.15.0 to wasp 0.16.2
Error:
[plugin:vite:import-analysis] Failed to resolve import "wasp/client/webSocket/WebSocketProvider" from "src/index.tsx". Does the file exist?
/home/rootall/apps/ask-the-documents/.wasp/out/web-app/src/index.tsx:12:34
8 | queryClientInitialized
9 | } from "wasp/client/operations";
10 | import { WebSocketProvider } from "wasp/client/webSocket/WebSocketProvider";
Code (wasp 0.15.0):
import { Server } from 'socket.io'
import { type WebSocketDefinition, type WaspSocketData } from 'wasp/server/webSocket'
What's wrong? What should be in latest wasp version? what's new? how to solve import?Let me check the knowledge base for you again. One moment! :books:
----------------------
It looks like you're encountering an import error after upgrading from Wasp 0.15.0 to 0.16.2. The error suggests that the import path for WebSocketProvider has changed in the newer version.
What's Changed in Wasp SDK Imports
Between Wasp versions, there have been changes to the SDK import paths. In Wasp 0.16.2, the import structure has been redesigned to be more intuitive and better organized.
Based on the error message, the import path
"wasp/client/webSocket/WebSocketProvider"
is no longer valid in Wasp 0.16.2.
How to Fix the Import
The most likely solution is to update your import path. In newer versions of Wasp, imports have been reorganized to follow a more logical structure with client/
, server/
, and possibly common/
prefixes.
Try changing your imports to:
General Migration Advice
When migrating between Wasp versions, especially for SDK imports, you may need to:
1. Run wasp clean
to clear any cached files
2. Check for any import path changes in the Wasp documentation
3. Update all @wasp
imports in your JS/TS files
If you're still having issues, you might need to follow the migration steps as described in the migration documentation.
The Wasp team has been working on improving the SDK import structure to make it clearer and more consistent, so these changes are part of that ongoing effort.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @NEROX, 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?forgot to refresh browser lol