Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

tsc inside Docker cannot find /tsconfig.json

Errorerror 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.

  • Applies to Docker 27, TypeScript 5, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 .
  2. 2Match what you see, then jump to its fix

    1. 1The error names /tsconfig.json with nothing before itThe build runs in / because no WORKDIR is setFix
    2. 2The file exists on your machine, but ls inside the image does not list ittsconfig.json never reaches the build contextFix
    3. 3The tsc command in the Dockerfile or in package.json has -p or --projecttsc is told to use another path than where the file isFix

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" Dockerfile

2Fix

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 tsc

3Verify

Rebuild the image without cache and check that the compile step passes.

docker build --no-cache -t app .

Confirmed by docs.docker.com

Did this fix it?

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 .dockerignore

2Fix

Remove the pattern that matches tsconfig.json. A line starting with ! makes an exception to an earlier exclusion.

# .dockerignore
node_modules
!tsconfig.json

3Verify

Rebuild and list the working folder.

docker build -t app . && docker run --rm app ls

Confirmed by docs.docker.com

Did this fix it?

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.json

2Fix

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.json

3Verify

Run the build again.

docker build -t app .

Confirmed by typescriptlang.org

Did this fix it?

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:

Related fixes

Back 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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.