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"]
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
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.
I can see you are trying to install
[email protected]
andajv-keywords@3
in the docker file.But as mentioned in the article, you need to install
ajv-keywords@5.*.*
whenajv
version8.*.*
is being used.If the ajv package version
6.*.*
, you can installajv-keywords@3.*.*
.npm list ajv
:I have created a react app and used below code in Dockerfile:
ajv(8.16.0)
andajv-keywords(5.0.1)
.