Facing an issue with wasp build when NODE_ENV is set to production
When i set NODE_ENV to production wasp build fails with Typescript errors for ImportMeta and env object. There are also module resolution failures for static files like svgs and pngs

2 Replies
Hi @ComputO. 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, here’s what’s relevant to your issue:
1. TypeScript Errors for
Your issues are likely due to mismatched or outdated
ImportMeta
and env
Object
- There was a known issue when moving from Create React App to Vite, where discrepancies between tsconfig.json
files caused IDEs and builds to report errors about import.meta
(which is how Vite exposes environment variables on the client). The solution is to ensure that the tsconfig.json
used for your client matches the one used by the build system, so that TypeScript recognizes import.meta
and its types correctly. If your tsconfig.json
is out of sync, you may see errors like the ones you described. This is a known issue and was being addressed to ensure consistency between the configs generated by Wasp for development and production builds. Make sure your project is using the latest Wasp version, and that the generated tsconfig.json
files are aligned as per the fix discussed in the issue. If you have custom changes, try regenerating or syncing your configs with the latest Wasp output Improve env vars docs, Ensure consistency between tsconfig.json files.
2. Module Resolution Failures for Static Files (SVGs, PNGs)
- The knowledge sources do not provide explicit details about static asset handling in production builds, but such issues are often related to Vite configuration or missing type declarations for static assets in TypeScript. If your tsconfig.json
or Vite config is missing the appropriate module declarations for images, TypeScript will fail to resolve them. This is also related to the tsconfig.json
consistency issue mentioned above Ensure consistency between tsconfig.json files.
3. Recommendations
- Check your Wasp version: Make sure you are using the latest version, as several issues with environment variables and TypeScript config have been addressed in recent releases.
- Sync your tsconfig.json
files: Ensure that the src/client/tsconfig.json
and .wasp/out/react-app/src/tsconfig.json
are consistent and include the necessary settings for Vite and static asset imports.
- Type Declarations for Static Assets: If you are importing SVGs or PNGs, ensure you have the appropriate type declarations (e.g., a declarations.d.ts
file with declare module "*.svg";
etc.).
- Environment Variables: For client-side env vars, use the REACT_APP_
prefix and access them via import.meta.env
. For server-side, use process.env
. Make sure you are not trying to access server env vars from the client or vice versa Docs: Env Variables.
If after these steps you still encounter issues, please provide the specific TypeScript error messages and your tsconfig.json
content for more targeted help.
If you are using a custom or older Wasp setup, or have made manual changes to the generated configs, updating to the latest Wasp and regenerating your project files may resolve these issues.
If you need more details on static asset handling or a specific error message, please share those for further assistance.
---
Summary:Your issues are likely due to mismatched or outdated
tsconfig.json
files and missing type declarations for static assets, both of which are known issues when moving to Vite and have been discussed in the Wasp community. Keeping your configs in sync and using the latest Wasp should resolve most of these problems. If not, please provide more details for further troubleshooting.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @ComputO, 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?- What's the usecase for calling with
NODE_ENV=production
?
- Does it fail with other NODE_ENV
values, or empty?
- Is this on wasp start
or wasp build
?