Skip to content

Commit ce5c9ac

Browse files
authored
docs(dockerfile): warn about the npm omit=dev + tsc build trap in TypeScript Actors (#2716)
1 parent c652a27 commit ce5c9ac

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

  • sources/platform/actors/development/actor_definition

sources/platform/actors/development/actor_definition/docker.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,48 @@ You can check out various optimization tips for Dockerfile in the [Performance](
204204

205205
:::
206206

207+
## Build TypeScript Actors
208+
209+
TypeScript Actors compile to JavaScript at build time through a `tsc` build step. Installing only production dependencies (`npm install --omit=dev`, or the older `--only=prod`) strips the `typescript` package, so the build fails with `tsc: not found`. Three fixes:
210+
211+
1. Multi-stage build (smallest runtime image, most complex Dockerfile). Installs dev dependencies in a builder stage, then copies the compiled output into a slim runtime stage.
212+
213+
```dockerfile
214+
FROM apify/actor-node:24 AS builder
215+
COPY --chown=myuser:myuser package*.json ./
216+
RUN npm install --include=dev
217+
COPY --chown=myuser:myuser . ./
218+
RUN npm run build
219+
220+
FROM apify/actor-node:24
221+
COPY --chown=myuser:myuser package*.json ./
222+
RUN npm install --omit=dev --omit=optional
223+
COPY --from=builder --chown=myuser:myuser /usr/src/app/dist ./dist
224+
CMD ["node", "dist/main.js"]
225+
```
226+
227+
1. Drop `--omit=dev` (simplest Dockerfile, largest runtime image). Installs everything, including linters and type declarations, into the single-stage image.
228+
229+
```dockerfile
230+
FROM apify/actor-node:24
231+
COPY --chown=myuser:myuser package*.json ./
232+
RUN npm install
233+
COPY --chown=myuser:myuser . ./
234+
RUN npm run build
235+
CMD ["node", "dist/main.js"]
236+
```
237+
238+
1. Move `typescript` to `dependencies`. Keeps the single-stage Dockerfile but bloats the runtime image with the TypeScript compiler and its tooling. The runtime never uses these, so the extra size is wasted.
239+
240+
```json
241+
{
242+
"dependencies": {
243+
"apify": "^3.4.0",
244+
"typescript": "^5.5.0"
245+
}
246+
}
247+
```
248+
207249
## Update older Dockerfiles
208250

209251
All Apify base Docker images now use a non-root user to enhance security. This change requires updates to existing Actor `Dockerfile`s that use the `apify/actor-node`, `apify/actor-python`, `apify/actor-python-playwright`, or `apify/actor-python-selenium` images. This section provides guidance on resolving common issues that may arise during this migration.

0 commit comments

Comments
 (0)