tsc inside Docker cannot find /tsconfig.json
error TS5083: Cannot read file '/tsconfig.json'.Short answer
TS5083 in a container means tsc looked for a tsconfig.json and the file is not there. The path /tsconfig.json shows it ran in the root folder. Set WORKDIR, copy tsconfig.json into it, and check that .dockerignore does not exclude it. Then run tsc from that folder.
Fix it fast
1Find out which cause you have
Print the working folder and its files right before the tsc step in the Dockerfile. The build output then shows whether the file is missing or only in another place.
RUN pwd && ls -la # build with: docker build --progress=plain .2Match what you see, then jump to its fix
- 1
The error names /tsconfig.json with nothing before itThe build runs in / because no WORKDIR is setFix - 2
The file exists on your machine, but ls inside the image does not list ittsconfig.json never reaches the build contextFix - 3
The tsc command in the Dockerfile or in package.json has -p or --projecttsc is told to use another path than where the file isFix
- 1
What does the error look like?
error TS5083: Cannot read file '/tsconfig.json'.
Cause 1 of 3
The build runs in / because no WORKDIR is set
1Check
The Dockerfile reference says that without WORKDIR the working directory is /. A COPY destination without a leading slash is relative to the working directory, so the files can end up elsewhere than where tsc runs.
grep -n "WORKDIR\|COPY\|tsc" Dockerfile2Fix
Set WORKDIR before the COPY lines, so the files and the compiler share one folder.
FROM node:22
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm ci
COPY tsconfig.json ./
COPY src ./src
RUN npx tsc3Verify
Rebuild the image without cache and check that the compile step passes.
docker build --no-cache -t app .Confirmed by docs.docker.com
Cause 2 of 3
tsconfig.json never reaches the build context
1Check
COPY reads from the build context, and files listed in .dockerignore are removed from it before the build, so COPY cannot find them. Also check that a COPY line for tsconfig.json exists.
cat .dockerignore2Fix
Remove the pattern that matches tsconfig.json. A line starting with ! makes an exception to an earlier exclusion.
# .dockerignore
node_modules
!tsconfig.json3Verify
Rebuild and list the working folder.
docker build -t app . && docker run --rm app lsConfirmed by docs.docker.com
Cause 3 of 3
tsc is told to use another path than where the file is
1Check
The TypeScript docs say --project takes a path to a config file or to a folder that holds tsconfig.json, and that tsc without options looks for the closest tsconfig.json from the current folder upward.
grep -rn "tsc" Dockerfile package.json2Fix
Point --project at the real location, or remove the flag and run tsc from the folder that holds the file.
RUN npx tsc --project ./tsconfig.json3Verify
Run the build again.
docker build -t app .Confirmed by typescriptlang.org
How do I stop it coming back?
- Always set WORKDIR in the Dockerfile instead of relying on the default.
- Review .dockerignore whenever a build step cannot find a file.
- Run the same build command locally in a clean checkout so path mistakes show before CI.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Back end
TypeScript cannot find '@angular/platform-browser' in an Angular project
Cannot find module '@angular/platform-browser' or its corresponding type declarations.
TS2307 means TypeScript could not turn the import into a file.
3 causes, each with a fixBack end
Angular build fails with TS2707 or "has no exported member" after installing a library
Module '"@angular/core"' has no exported member
These errors mean a library was compiled by a newer Angular than your app uses.
3 causes, each with a fixBack end
cdk synth says --app is required
--app is required either in command-line, in cdk.json or in ~/.cdk.json
The CDK CLI needs a command that runs your app and finds it in three places: the --app option, cdk.json in the project folder, or cdk.json in your home folder.
3 causes, each with a fixBack end
TypeScript cannot find module '@nestjs/core' or its type declarations
error TS2307: Cannot find module '@nestjs/common' or its corresponding type declarations.
TS2307 means TypeScript searched node_modules and found neither the package nor its types.
3 causes, each with a fixBack end
Mocha or Node cannot find ts-node/register
Error: Cannot find module 'ts-node/register'
Node resolves ts-node/register from your project's node_modules, so the package must be installed there, next to typescript.
2 causes, each with a fixBack end
TypeError: Class constructor cannot be invoked without 'new' in compiled TypeScript
TypeError: Class constructors cannot be invoked without 'new'
Node.js throws this when a native class is called like a plain function.
2 causes, each with a fix