Search code examples
node.jstypescriptdocker-composedockerfile

error TS5083: Cannot read file '/tsconfig.json'


I am trying to run the command "tsc --build" when running "docker compose up --build" so it can run that command when creating the Docker container.

The thing is I am getting always an error:

enter image description here

I have been reading about it and I am not importing in my code anything outside the "rootdir"... so I have no idea why those packages are there...

I am not sure if removing the rootdir option from tsconfig file is a good idea or it would cause an error afterwards in my app...

Any ideas?


Solution

  • You need to copy your tsconfig.json to your Docker image.

    Add the following after line 5:

    COPY tsconfig.json ./

    Notes:

    • You probably need to also copy the nodemon.json
    • At the line 10 you copy all the current directory to your image, ensure your .dockerignore file contain a rule to exclude the node_modules/, dist/ folders.