How to fix Cannot find module '../lib/cli' nodemon in Node deployment to Azure

Liz Melamed 0 Reputation points
2023-06-05T21:19:39.9066667+00:00

For a week now I'm trying to deploy my Nodejs - React to web service with git Actions.

I tried to reinstall nodemon, I tried to add in my workflow an explicit nodemon global download, but nothing seems to work.

How can I resolve this?

I'm always getting this error :

export NODE_PATH=/usr/local/lib/node_modules:$NODE_PATH
2023-06-05T16:03:30.613684171Z if [ -z "$PORT" ]; then
2023-06-05T16:03:30.613687871Z 		export PORT=8080
2023-06-05T16:03:30.613691971Z fi
2023-06-05T16:03:30.613695471Z 
2023-06-05T16:03:30.615420031Z npm start
2023-06-05T16:03:32.033435232Z npm info using n******@9.6.4
2023-06-05T16:03:32.036983955Z npm info using n******@v16.20.0
2023-06-05T16:03:32.146052335Z 
2023-06-05T16:03:32.146153939Z > m******@1.0.0 start
2023-06-05T16:03:32.146164039Z > nodemon
2023-06-05T16:03:32.146168639Z 
2023-06-05T16:03:32.372833495Z node:internal/modules/cjs/loader:1029
2023-06-05T16:03:32.372899597Z   throw err;
2023-06-05T16:03:32.372906198Z   ^
2023-06-05T16:03:32.372910198Z 
2023-06-05T16:03:32.372989500Z Error: Cannot find module '../lib/cli'
2023-06-05T16:03:32.372997901Z Require stack:
2023-06-05T16:03:32.373001901Z - /home/site/wwwroot/node_modules/.bin/nodemon
2023-06-05T16:03:32.373005601Z     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1026:15)
2023-06-05T16:03:32.373009301Z     at Function.Module._load (node:internal/modules/cjs/loader:871:27)
2023-06-05T16:03:32.373013001Z     at Module.require (node:internal/modules/cjs/loader:1098:19)
2023-06-05T16:03:32.373016601Z     at require (node:internal/modules/cjs/helpers:108:18)
2023-06-05T16:03:32.373031602Z     at Object. (/home/site/wwwroot/node_modules/.bin/nodemon:3:13)
2023-06-05T16:03:32.373035702Z     at Module._compile (node:internal/modules/cjs/loader:1196:14)
2023-06-05T16:03:32.373039302Z     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
2023-06-05T16:03:32.373043002Z     at Module.load (node:internal/modules/cjs/loader:1074:32)
2023-06-05T16:03:32.373046602Z     at Function.Module._load (node:internal/modules/cjs/loader:909:12)
2023-06-05T16:03:32.373050203Z     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
2023-06-05T16:03:32.373053903Z   code: 'MODULE_NOT_FOUND',
2023-06-05T16:03:32.373057503Z   requireStack: [ '/home/site/wwwroot/node_modules/.bin/nodemon' ]
2023-06-05T16:03:32.373061503Z }

This is my workflow:

on:
  push:
    branches: [ "master" ]
  workflow_dispatch:

env:
  AZURE_WEBAPP_NAME: ------    # set this to your application's name
  AZURE_WEBAPP_PACKAGE_PATH: '.'      # set this to the path to your web app project, defaults to the repository root
  NODE_VERSION: '16.20.0'                # set this to the node version to use

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3

    - name: Set up Node.js
      uses: actions/setup-node@v3
      with:
        node-version: ${{ env.NODE_VERSION }}
        cache: 'npm'

    - name: npm install, build, and test
      run: |
        npm install
        npm run build --if-present
        npm run test --if-present
        npx webpack
        

    - name: Upload artifact for deployment job
      uses: actions/upload-artifact@v3
      with:
        name: node-app
        path: .

  deploy:
    permissions:
      contents: none
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Development'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
    - name: Download artifact from build job
      uses: actions/download-artifact@v3
      with:
        name: node-app

    - name: 'Deploy to Azure WebApp'
      id: deploy-to-webapp
      uses: azure/webapps-deploy@v2
      with:
        app-name: ${{ env.AZURE_WEBAPP_NAME }}
        publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
        package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,956 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 22,521 Reputation points Microsoft Employee
    2023-06-06T18:32:32.1466667+00:00

    Liz Melamed, Apologies, you’re experiencing this issue for a week now. I also see that you have posted the question on SO.

    Just to clarify, does your app deployment work fine locally? What specific framework are you leveraging?

    At a high level, seeing error: cannot find module [ModuleName] means this package required by your application is missing in some form. I understand you have tried to reinstall and explicitly indicated it.

    Just to highlight, if you’re deploying the app with the default Typescript based package.json. Oryx will try to run npm start if so, causing TypeScript to be recompiled during container start up. To resolve this, change the package.json as mentioned the sample below.

    You may try to change npm start to use node lib/index.js to target the compiled, entrypoint under lib/.

    "start": "node lib/index.js",
    

    -- App Service NodeJs samples:

    Take a look at the step-step instructions to isolate the issue further.

    Troubleshooting Node.js deployments on App Service Linux

    Module not found with Node on App Service Linux

    Kindly let us know, I'll follow-up with you further.

    0 comments No comments