Unable wasp start with setting NODE_ENV=production
I have issue when I set NODE_ENV=production. If I set to development, it works.
Can someone explain and tell me how to fix?
60.07 [ Wasp ] client/config.ts(3,47): error TS2339: Property 'env' does not exist on type 'ImportMeta'.
60.07 [ Wasp ] ext-src/admin/layout/Sidebar.tsx(3,18): error TS2307: Cannot find module '../../client/static/logo.png' or its corresponding type declarations.
60.07 [ Wasp ] ext-src/auth/AuthPageLayout.tsx(2,29): error TS2307: Cannot find module '../../src/client/static/niles_background.png' or its corresponding type declarations.
60.07 [ Wasp ] ext-src/client/App.tsx(9,18): error TS2307: Cannot find module '../../src/client/static/logo5.png' or its corresponding type declarations.
60.07 [ Wasp ] ext-src/client/components/AppHeader2.tsx(5,18): error TS2307: Cannot find module '../static/logo4.png' or its corresponding type declarations.
60.07 [ Wasp ] ext-src/client/components/cookie-consent/Config.ts(16,31): error TS2339: Property 'env' does not exist on type 'ImportMeta'.
60.07 [ Wasp ] ext-src/client/components/cookie-consent/Config.ts(61,53): error TS2339: Property 'env' does
2 Replies
Hi @binhnguyenquoc.. 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 information provided in the knowledge sources, I can explain the issue you're experiencing and suggest some potential solutions.
The error you're seeing is related to how environment variables and TypeScript configurations are handled in Wasp, particularly when building for production.
1. Environment Variables in Production:
When building for production, client-side environment variables need to be handled differently compared to development. As explained in the Env Variables documentation, client env vars are embedded into the client code during the build process.
For production builds, you should provide the environment variables to the build command, like this:
or for Wasp:
2. TypeScript Configuration:
The errors you're seeing, particularly
Property 'env' does not exist on type 'ImportMeta'
, are likely due to a discrepancy between the TypeScript configurations used in development and production. This issue is mentioned in a GitHub issue about tsconfig.json consistency.
To resolve this, you might need to ensure that your tsconfig.json
file includes the correct configuration for import.meta.env
. However, modifying the TypeScript configuration might require changes to the Wasp framework itself.
3. Module Resolution Errors:
The errors about not finding modules (like Cannot find module '../../client/static/logo.png'
) might be related to how static assets are handled in the production build. Make sure that these files are in the correct locations and that your build process is configured to handle these imports correctly.
To fix these issues:
1. Ensure you're providing the necessary environment variables during the build process as mentioned above.
2. Check if there's an updated version of Wasp that might have resolved these TypeScript configuration issues.
3. If you're using custom TypeScript configurations, make sure they're compatible with both development and production builds.
If the problem persists, you might want to consider opening an issue on the Wasp GitHub repository or seeking help on their Discord channel, as this seems to be a framework-specific issue that might require attention from the Wasp team.
Remember, setting NODE_ENV=production
triggers different behaviors in many JavaScript tools and frameworks, so it's important to ensure your entire build and deployment process is configured correctly for production use.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @binhnguyenquoc., 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 have issue when I set NODE_ENV=production. If I set to development, it works.Could you be more specific? Where do you set the
NODE_ENV
variable? Which commands are you running?