6

I have developed a Next.js app that works fine on my local machine. I am trying to deploy my app on Vercel but it keeps throwing me the error Cannot find module '@next/env' as shown here.

enter image description here

I think it's because of the next-sitemap package. I have checked my node modules and there is no env file or folder inside the @next folder. I have also researched around but haven't been able to find any solution.

I have also tried deploying my app on Netlify and it throws the same error. Any help would be appreciated a lot.

UPDATE: I was finally able to solve this by updating my next.js to 10.2.3

  • Can you share your package.json? You may want to try generating a fresh lock file by deleting it + node_modules and re-running `npm install`. Possibly a global package installation on your machine is causing it to work, but you can't rely on that. – JBallin Jun 23 '21 at 16:34
  • @JBallin I thought about doing that too but couldn't understand how would it affect my deployment on Vercel? I don't have `package-lock.json` on my repo. My package.json file is [this](https://i.imgur.com/BYhuEU2.png) – Muhammad Mutahhar Bin Muzaffar Jun 23 '21 at 17:07
  • Why don't you have a lockfile? Do you have a link to the repo? – JBallin Jun 23 '21 at 17:30
  • Well, I honestly didn't know you have to add the lock file as well. Anyways, after a lot on unsuccessful tries, I was finally able to deploy my site after updating next js to 10.2.3 – Muhammad Mutahhar Bin Muzaffar Jun 23 '21 at 18:56

1 Answers1

1

just add "@next/env": "^12.0.7" inside dependencies in your package file or just write npm install @next/env

mkm_09
  • 11
  • 3