skip to Main Content

I have a React app that is being deployed in Azure App Service through the Azure container registry so it is using a Docker image.

It has been working up until last week when the startup of the app is failing due to the error Cannot find module ‘ajv/dist/compile/codegen’.

The app starts fine locally, using both npm start and a docker image so it is just happening when I am trying to deploy through the app service.

Output from command npm list ajv. Note all of these are dependencies of libraries I am using, I do not directly use this package.

── [email protected]
└─┬ [email protected]
  ├─┬ @pmmmwh/[email protected]
  │ └─┬ [email protected]
  │   ├─┬ [email protected]
  │   │ └── [email protected] deduped
  │   ├─┬ [email protected]
  │   │ └── [email protected] deduped
  │   └── [email protected] deduped
  ├─┬ [email protected]
  │ └─┬ [email protected]
  │   ├─┬ [email protected]
  │   │ └── [email protected] deduped
  │   └── [email protected]
  ├─┬ [email protected]
  │ ├─┬ @eslint/[email protected]
  │ │ └── [email protected]
  │ └── [email protected]
  ├─┬ [email protected]
  │ └─┬ [email protected]
  │   ├─┬ [email protected]
  │   │ └── [email protected] deduped
  │   └── [email protected]
  ├─┬ [email protected]
  │ └─┬ [email protected]
  │   └─┬ [email protected]
  │     ├─┬ [email protected]
  │     │ └── [email protected] deduped
  │     └── [email protected]
  ├─┬ [email protected]
  │ └─┬ [email protected]
  │   ├─┬ [email protected]
  │   │ └── [email protected] deduped
  │   └── [email protected]
  ├─┬ [email protected]
  │ └─┬ [email protected]
  │   ├─┬ [email protected]
  │   │ └── [email protected] deduped
  │   └── [email protected]
  └─┬ [email protected]
    └─┬ [email protected]
      ├─┬ @apideck/[email protected]
      │ └── [email protected] deduped
      └── [email protected] deduped

This is my docker file, I have tried multiple versions of ajv installation but none have worked.

FROM node:20.11-alpine
WORKDIR /frontend
COPY . .
COPY .babelrc /frontend
RUN npm config set legacy-peer-deps true
RUN npm install --legacy-peer-deps
RUN npm install --force
RUN npm install [email protected] ajv-keywords@3 --force
RUN npm install @azure/msal-browser --legacy-peer-deps
RUN npm install @azure/msal-react --legacy-peer-deps
RUN npm install @material-ui/core --force
RUN npm install @babel/preset-react --force
RUN npm install @babel/preset-env --force
RUN npm install -g react-scripts
EXPOSE 3000
CMD ["sh", "-c", "npm install && npm run start"]

Tried this answer

Also deleted node_modules and package-lock.json to run a fresh install but this has not worked either.

Is there anything I am missing or need to do to get this resolved?

2

Answers


  1. Chosen as BEST ANSWER

    I have a solution that appears to have worked. I added the line below in dockerfile to install the package globally in the container which has let react-scripts find it.

    RUN npm install -g [email protected]

    Thanks everyone for suggestions, I had tried loads of different combinations of versions with no luck but this has removed the error.


  2. I can see you are trying to install [email protected] and ajv-keywords@3 in the docker file.

    • But as mentioned in the article, you need to install ajv-keywords@5.*.* when ajv version 8.*.* is being used.

    • If the ajv package version 6.*.*, you can install ajv-keywords@3.*.* .

    enter image description here

    • The same has been available in the provided output of npm list ajv:
    ── [email protected]
    └─┬ [email protected]
      ├─┬ @pmmmwh/[email protected]
      │ //Removed few modules
      │   ├─┬ [email protected]
    
      ├─┬ [email protected]
      │ └─┬ [email protected]
      │   ├─┬ [email protected]
      │   │ └── [email protected] deduped
      │   └── [email protected]
      │ ////Removed few modules
    
    • Remove force and use Save instead in the command in Docker File.
    npm install [email protected] [email protected] --Save
    

    I have created a react app and used below code in Dockerfile:

    # Fetching the latest node image on alpine linux
    FROM node:alpine AS development
    
    # Installing dependencies
    COPY package*.json .
    
    RUN npm install
    
    # Copying all the files in our project
    COPY . .
    
    EXPOSE 3000
    
    # Starting our application
    CMD ["npm","start"]
    
    • Installed latest packages of ajv(8.16.0) and ajv-keywords(5.0.1).

    enter image description here

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search