Error: Cannot find module 'dotenv/config'

It happens quite often, just by starting the project. (I'm on Wasp 0.15.2) same with older versions. I have to do wasp clean and wasp install (which takes a while). I'm with W10 WSL Any solution?
:bee: --- Starting compilation and setup phase. Hold tight... ------------------------


:bee: --- Compiling wasp project... --------------------------------------------------


:white_check_mark: --- Successfully completed npm install. ----------------------------------------


:bee: --- Setting up database... -----------------------------------------------------


:white_check_mark: --- Database successfully set up. ----------------------------------------------


:bee: --- Building SDK... ------------------------------------------------------------


:white_check_mark: --- SDK built successfully. ----------------------------------------------------


:white_check_mark: --- Your wasp project has successfully compiled. -------------------------------


:bee: --- Listening for file changes... ----------------------------------------------


:bee: --- Starting up generated project... -------------------------------------------


[ Client ] > [email protected] start
[ Client ] > npm run validate-env && vite
[ Client ]
[ Server ] > [email protected] watch
[ Server ] > nodemon --exec 'npm run bundle-and-start || exit 1'
[ Server ]
[ Client ]
[ Client ] > [email protected] validate-env
[ Client ] > node -r dotenv/config ./scripts/validate-env.mjs
[ Client ]
[ Client!] node:internal/modules/cjs/loader:1143
[ Client!] throw err;
[ Client!] ^
[ Client!]
[ Client!] Error: Cannot find module 'dotenv/config'
[ Client!] Require stack:
[ Client!] - internal/preload
[ Client!] at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
[ Client!] at Module._load (node:internal/modules/cjs/loader:981:27)
[ Client!] at internalRequire (node:internal/modules/cjs/loader:174:19)
[ Client!] at Module._preloadModules (node:internal/modules/cjs/loader:1569:5)
[ Client!] at loadPreloadModules (node:internal/process/pre_execution:628:5)
[ Client!] at setupUserModules (node:internal/process/pre_execution:154:3)
[ Client!] at prepareExecution (node:internal/process/pre_execution:114:5)
[ Client!] at prepareMainThreadExecution (node:internal/process/pre_execution:40:10)
[ Client!] at node:internal/main/run_main_module:11:19 {
[ Client!] code: 'MODULE_NOT_FOUND',
[ Client!] requireStack: [ 'internal/preload' ]
[ Client!] }
[ Client!]
[ Client!] Node.js v18.20.4
:bee: --- Starting compilation and setup phase. Hold tight... ------------------------


:bee: --- Compiling wasp project... --------------------------------------------------


:white_check_mark: --- Successfully completed npm install. ----------------------------------------


:bee: --- Setting up database... -----------------------------------------------------


:white_check_mark: --- Database successfully set up. ----------------------------------------------


:bee: --- Building SDK... ------------------------------------------------------------


:white_check_mark: --- SDK built successfully. ----------------------------------------------------


:white_check_mark: --- Your wasp project has successfully compiled. -------------------------------


:bee: --- Listening for file changes... ----------------------------------------------


:bee: --- Starting up generated project... -------------------------------------------


[ Client ] > [email protected] start
[ Client ] > npm run validate-env && vite
[ Client ]
[ Server ] > [email protected] watch
[ Server ] > nodemon --exec 'npm run bundle-and-start || exit 1'
[ Server ]
[ Client ]
[ Client ] > [email protected] validate-env
[ Client ] > node -r dotenv/config ./scripts/validate-env.mjs
[ Client ]
[ Client!] node:internal/modules/cjs/loader:1143
[ Client!] throw err;
[ Client!] ^
[ Client!]
[ Client!] Error: Cannot find module 'dotenv/config'
[ Client!] Require stack:
[ Client!] - internal/preload
[ Client!] at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
[ Client!] at Module._load (node:internal/modules/cjs/loader:981:27)
[ Client!] at internalRequire (node:internal/modules/cjs/loader:174:19)
[ Client!] at Module._preloadModules (node:internal/modules/cjs/loader:1569:5)
[ Client!] at loadPreloadModules (node:internal/process/pre_execution:628:5)
[ Client!] at setupUserModules (node:internal/process/pre_execution:154:3)
[ Client!] at prepareExecution (node:internal/process/pre_execution:114:5)
[ Client!] at prepareMainThreadExecution (node:internal/process/pre_execution:40:10)
[ Client!] at node:internal/main/run_main_module:11:19 {
[ Client!] code: 'MODULE_NOT_FOUND',
[ Client!] requireStack: [ 'internal/preload' ]
[ Client!] }
[ Client!]
[ Client!] Node.js v18.20.4
No description
5 Replies
kapa.ai
kapa.ai3d ago
Hi @NEROX. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- This error is related to running Wasp projects on Windows using WSL (Windows Subsystem for Linux). The issue you're experiencing is likely due to file system incompatibilities between Windows and WSL. Let me provide some insights and potential solutions: 1. File System Location: Make sure your Wasp project is located on the Linux file system within WSL, not on the Windows file system. This is crucial for proper file change detection and overall performance. Wasp WSL Guide (https://wasp-lang.dev/blog/2023/11/21/guide-windows-development-wasp-wsl) recommends this approach. 2. WSL2 File Change Detection: There's a known issue with WSL2 not detecting file changes properly when projects are on the Windows file system. This can cause problems with hot reloading and other development features. Github Issue (https://github.com/wasp-lang/wasp/issues/603) 3. Clean and Reinstall: As you've mentioned, running wasp clean followed by wasp start (which includes installation) can sometimes resolve these issues. This is a valid temporary workaround. 4. Environment Variables: Ensure that your environment variables are set correctly. Wasp uses .env.server and .env.client files for environment variables. Make sure these files exist and are properly configured. Wasp Env Vars Docs (https://wasp-lang.dev/docs/project/env-vars#defining-env-vars-in-development) 5. Node.js Version: Verify that you're using a compatible Node.js version. Wasp works best with LTS versions of Node.js. 6. Permissions: Check if there are any permission issues with your project files and directories within WSL. To potentially resolve this issue: 1. Move your project to the Linux file system within WSL if it's not already there. 2. Run wasp clean to remove all generated files and dependencies. 3. Ensure your .env.server and .env.client files are present and correctly configured. 4. Run wasp start to reinstall dependencies and start the project. If the issue persists, you might want to check for any conflicts with global Node.js installations or PATH issues within your WSL environment. For more detailed assistance, you can reach out to the Wasp community on Discord (https://discord.gg/rzdnErX), where other developers using WSL might be able to provide more specific guidance. ---------------------- 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?
NEROX
NEROXOP3d ago
:( I have everything installed correctly and when I least expect it, I get this error, and I have to delete and reinstall everything :((
miho
miho3d ago
Could you share a list of commands you run before this start happening? Are you maybe running npm install directly or smth like that?
NEROX
NEROXOP3d ago
Nope, everytime i just run wasp start to start the app. If I need dependencies, I stop it, install them, run wasp start and it works perfectly. Sometimes it crashes out of nowhere, sometimes not.
miho
miho3d ago
Hm, I never got this error, so I don't know what we can do to debug next. Maybe you can create a new project with wasp new and try running it and see what happens? Also, could you maybe upload your package-lock.json file from .wasp/out/web-app when it happens again?
Want results from more Discord servers?
Add your server