I’m trying to dockerize a react app (created with cra) with typescript (typescript was added manually later and not with cra)

This is my file structure:

<my app>
├── node_modules/
├── public/
├── src/
├── package.json
├── Dockerfile
└── tsconfig.json

This is my Dockerfile:

FROM node:alpine3.18

WORKDIR /app

ENV NODE_ENV=production

RUN apk add --no-cache npm

COPY . /app

RUN npm install
RUN npm run build

CMD [ "npm", "run", "start" ]

EXPOSE 443

All works fine until the build step, it gives me this error:

Module not found: Error: Can't resolve 'redux-logger' in '/app/src/redux'

Which is correct, ‘redux-logger’ is not in ‘/app/src/redux’, but I’m importing ‘redux-logger’ from node_modules and not from a local directory. The import statement is located in /src/redux/redux-store.ts:

import logger from 'redux-logger'

So react should be looking into node_modules and not in my src directory for the logger, I don’t know why it behaves like that when running the build script from docker, when I build my app locally without docker it builds just fine.

Just in case this is my tsconfig.json content:

{
  "compilerOptions": {
    "target": "es6",
    "lib": ["es5", "es6", "dom", "dom.iterable", "esnext"],
    "downlevelIteration": true,
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": ["src", "src/custom.d.ts"]
}

Like I said this works just fine in local but docker gives me that error, what could I be missing here?