I am encountering a problem with my node project which serves a simple "hello world" server. Everything runs smoothly when I run it locally, but when I try to run it inside Docker, a /opt/yarn-v1.21.1 folder is created which leads to a rootDir error:
error TS6059: File '/opt/yarn-v1.21.1/bin/yarn.js' is not under 'rootDir' '/opt/src'. 'rootDir' should contain all source files.
This is what my Dockerfile looks like:
FROM node:13.8.0-alpine
WORKDIR /opt
COPY package*.json ./
COPY tsconfig*.json ./
RUN npm i --quiet
Here's the snippet from my tsconfig file:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["es6"],
"allowJs": true,
"outDir": "dist",
"rootDir": "src",
"strict": true,
"noImplicitAny": true,
"esModuleInterop": true,
"resolveJsonModule": true,
},
}
And here's a section from my package.json file:
{
"name": "test-api",
"scripts": {
"dev": "tsc",
"start:dev": "tsc && concurrently \"tsc -w\" \"nodemon dist/app.js\""
},
"dependencies": {
"@types/node": "^13.7.0",
"concurrently": "^5.1.0",
"nodemon": "^2.0.2",
"typescript": "^3.7.5"
}
}
I would appreciate any insights as to why this discrepancy occurs when running the project through Docker. My initial thought was that yarn might already be installed on my system, but docker creates it within the image by default.
Changing the rootDir from /src
to ./
resolves the error, but it results in the following output structure in the dist folder:
dist
src
app.js
yarn-v1.21.1
Instead of the desired structure:
dist
app.js