I have the following Dockerfile which is failing at the step which compiles TypeScript:
FROM node:12
WORKDIR /usr/src/app
# SETUP
COPY package.json .
COPY tsconfig.json .
COPY src .
RUN npm install -g yarn@^1.16.0
RUN yarn install
# BUILD
RUN npx tsc <------------------------
The error message is very confusing:
File '/usr/src/app/app.ts' is not under 'rootDir' '/usr/src/app/src'. 'rootDir' is expected to contain all source files.
This makes no sense... It's finding app.ts under the src folder and then complaining that it isn't under the src folder.
Files:
src
app.ts
tsconfig.json
Dockerfile
How do I solve this issue?
Here is my tsconfig.json:
{
"compilerOptions": {
...
"rootDir": "./src",
"outDir": "./build",
...
}
}
Wow, it was such a simple problem unrelated to TypeScript.
I didn't do the COPY command correctly.
When copying files you can do COPY <filename> .
But apparently for directories you must do COPY <dirname> <dirname>
So I fixed this by changing COPY src . to COPY src src.