Vite 4.0.0 not working with netlify-cli 12.4.0 / ntl deploy live? It is! Its a Vite/ DOTENV issue!

Netlify site name: astonishing-chimera-958017

I had an app running fine locally and using ntl deploy live with netlify-cli 12.4.0 and vite 3.2.5. It had a “Projects” link that displayed all projects and this worked locally and live. It used a netlify function which used DOTENV.

Now, Im running with Vite 4.0.0, still netlify-cli 12.4.0 and works locally but “ntl deploy live” would NOT show the list of projects. Rest of site worked. Build worked, only accessing the Netlify functions failed with deploy live.

So I thought it was a Vite change issue. However, wasnt getting expected result so switched back to current Vite (4.0.0) then noticed mongodb had changed so reverted to earlier version. Didnt work.

Next I recalled issued with Vite and DOTENV so I removed dotenv and tested with hardcoded variables, now removed and the live deploy works. I had earlier added the environment variables to the temporary website but that didnt work, perhaps because it wasnt “deployed” and just temporary?

So it looks like I have to switch to the new Vite/Svelte style of handling environment variables and drop dotenv.

I’m not sure what you’re trying. netlify deploy live doesn’t seem to be a valid command: Netlify CLI deploy command

Sorry about that. Yes it was ntl deploy --prod. But you can mark this as closed. I just discovered that Sveltekit/Vite doesnt like “require” which I was using for dotenv. It didnt matter locally but when deployed it failed. But I found that using “import” instead worked fine, so thats the fix. Thanks.

1 Like

Thank you for sharing your solution! This is definitely helpful for other users