MODULE_NOT_FOUND error for next

Abdelkhalek Bakkari 45 Reputation points
2025-04-04T18:25:28.96+00:00

I am deploying a nextjs web app to Azure App Service, but I am getting the error below :
2025-04-04T17:36:00 Welcome, you are now connected to log-streaming service.Starting Log Tail -n 10 of existing logs ----/home/LogFiles/__lastCheckTime.txt (https://smartovateweb.scm.azurewebsites.net/api/vfs/LogFiles/__lastCheckTime.txt)04/04/2025 17:34:38/home/LogFiles/kudu/trace/d1e0df7f9d2b-83a59703-a08d-4094-ad5c-a3853cad047b.txt (https://smartovateweb.scm.azurewebsites.net/api/vfs/LogFiles/kudu/trace/d1e0df7f9d2b-83a59703-a08d-4094-ad5c-a3853cad047b.txt)

2025-04-04T16:45:14 Startup Request, url: /api/logstream/, method: GET, type: request, pid: 821,1,7, ScmType: None/home/LogFiles/kudu/trace/d45adeb592f3-7b81b6cf-85bb-41c5-894e-6f40200bd235.txt (https://smartovateweb.scm.azurewebsites.net/api/vfs/LogFiles/kudu/trace/d45adeb592f3-7b81b6cf-85bb-41c5-894e-6f40200bd235.txt)

2025-04-04T16:40:34 Startup Request, url: /api/logstream/, method: GET, type: request, pid: 823,1,5, ScmType: None/home/LogFiles/kudu/trace/smartovate-kudu-a3dacac7-2ebeca5f-5731-4f70-999a-395245259cef.txt (https://smartovateweb.scm.azurewebsites.net/api/vfs/LogFiles/kudu/trace/smartovate-kudu-a3dacac7-2ebeca5f-5731-4f70-999a-395245259cef.txt)

2025-04-04T16:11:42 Startup Request, url: /api/settings, method: GET, type: request, pid: 822,1,7, ScmType: None/home/LogFiles/2025_04_04_lw1sdlwk0009V2_default_docker.log (https://smartovateweb.scm.azurewebsites.net/api/vfs/LogFiles/2025_04_04_lw1sdlwk0009V2_default_docker.log)

2025-04-04T17:35:12.849532421Z at Module._load (node:internal/modules/cjs/loader:1104:12)

2025-04-04T17:35:12.849536586Z at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:173:12) {

2025-04-04T17:35:12.849540859Z code: 'MODULE_NOT_FOUND',

2025-04-04T17:35:12.849545018Z requireStack: [ '/home/site/wwwroot/node_modules/.bin/next' ]

2025-04-04T17:35:12.849549234Z }

2025-04-04T17:35:12.849553239Z

2025-04-04T17:35:12.849557277Z Node.js v20.18.3

2025-04-04T17:35:12.940727710Z error Command failed with exit code 1.

2025-04-04T17:35:12.947938225Z info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command./home/LogFiles/2025_04_04_lw1sdlwk0009V2_docker.log (https://smartovateweb.scm.azurewebsites.net/api/vfs/LogFiles/2025_04_04_lw1sdlwk0009V2_docker.log)

2025-04-04T17:13:01.626Z ERROR - Container smartovateweb_0_6aae8464 didn't respond to HTTP pings on port: 8080, after 34.3818418 sec. Failing site start. See container logs for debugging.

2025-04-04T17:13:01.718Z INFO - Stopping site smartovateweb because it failed during startup.

2025-04-04T17:34:41.416Z INFO - Starting container for site

2025-04-04T17:34:41.423Z INFO - docker run -d --expose=8080 --name smartovateweb_0_0140b801 -e WEBSITE_USE_DIAGNOSTIC_SERVER=true -e WEBSITE_SITE_NAME=smartovateweb -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=smartovateweb.azurewebsites.net -e WEBSITE_INSTANCE_ID=b42e8886acdb8a5a6fd64d57ead538cc2765d75cbbc61a37cab2678ae174bea0 appsvc/node:20-lts_20250303.1.tuxprod REDACTED

2025-04-04T17:34:41.424Z INFO - Logging is not enabled for this container.Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.

2025-04-04T17:34:44.770Z INFO - Initiating warmup request to container smartovateweb_0_0140b801 for site smartovateweb

2025-04-04T17:35:13.942Z ERROR - Container smartovateweb_0_0140b801 for site smartovateweb has exited, failing site start

2025-04-04T17:35:14.016Z ERROR - Container smartovateweb_0_0140b801 didn't respond to HTTP pings on port: 8080, after 35.111712 sec. Failing site start. See container logs for debugging.

2025-04-04T17:35:14.092Z INFO - Stopping site smartovateweb because it failed during startup.Ending Log Tail of existing logs ---Starting Live Log Stream ---

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,930 questions
{count} votes

Accepted answer
  1. Suresh Chikkam 2,135 Reputation points Microsoft External Staff Moderator
    2025-04-08T06:11:03.19+00:00

    Hi Abdelkhalek Bakkari,

    You are currently using yarn dev in production, which is meant only for local development. Azure App Service expects a production-ready application, and that's why the deployment is failing.

    In package.json, you need to change the start script. Right now, it's likely running next start, which doesn't work properly if you're using the standalone output mode in Next.js.

    Update the package.json like this:

    
    {
    
      "scripts": {
    
        "build": "next build",
    
        "start": "node .next/standalone/server.js",
    
        "postinstall": "next build"
    
      }
    
    }
    
    

    next.config.js should contains this:

    module.exports = {
      output: 'standalone',
    };
    

    Next, update the GitHub Actions workflow. Right now, the startup command in Azure is trying to run yarn dev, which should be replaced with the proper production start command.

    Change this line:

    
    az webapp config set --resource-group "Smartovate" --name "smartovateweb" --startup-file "yarn install && yarn dev --port 8080"
    
    

    To this:

    
    az webapp config set --resource-group "Smartovate" --name "smartovateweb" --startup-file "yarn install && yarn build && yarn start"
    
    

    Then the app will build and started in production mode.

    You should also check the GitHub Actions zip step includes the necessary build output. If you're using the standalone mode, zip at least the .next, public, node_modules, package.json, and yarn.lock files:

    zip -r release.zip .next/ public/ node_modules/ package.json yarn.lock
    

    Push the changes and let the workflow deploy again. The app should now start correctly on Azure. Let me know if you'd like me to adjust your full workflow file with all of this applied.

    Hope it helps!


    Please do not forget to click "Accept the answer” and Yes wherever the information provided helps you, this can be beneficial to other community members.

    User's image

    If you have any other questions or still running into more issues, let me know in the "comments" and I would be happy to help you.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.