Skip to content

Commit 28ae81a

Browse files
VladUZHclaude
andcommitted
fix: rebuild shared package as CommonJS in Docker for Node.js compat
The shared package uses moduleResolution:bundler which allows bare directory imports. Node.js ESM doesn't support these. Rebuild as CommonJS in the Docker build stage for runtime compatibility. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3eefd85 commit 28ae81a

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

apps/api/Dockerfile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ RUN cp -r apps/api/src/generated apps/api/dist/generated
3737
RUN npm ci --workspace=apps/api --workspace=packages/shared --omit=dev --ignore-scripts
3838

3939
# Point shared package exports to compiled dist for production runtime
40-
RUN node -e "\
41-
const fs = require('fs'); \
42-
const pkg = JSON.parse(fs.readFileSync('packages/shared/package.json', 'utf8')); \
43-
pkg.main = './dist/index.js'; \
44-
pkg.exports = { '.': { types: './dist/index.d.ts', default: './dist/index.js' } }; \
45-
fs.writeFileSync('packages/shared/package.json', JSON.stringify(pkg, null, 2));"
40+
# Rebuild shared as CommonJS for Node.js runtime compatibility
41+
# (source uses moduleResolution:bundler which allows directory imports,
42+
# but Node.js ESM doesn't support them)
43+
RUN cd packages/shared && rm -rf dist && \
44+
npx tsc --outDir dist --module commonjs --moduleResolution node --declaration --sourceMap --esModuleInterop && \
45+
node -e "\
46+
const fs = require('fs'); \
47+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); \
48+
pkg.main = './dist/index.js'; \
49+
pkg.exports = { '.': { types: './dist/index.d.ts', default: './dist/index.js' } }; \
50+
delete pkg.type; \
51+
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));"
4652

4753
# ── Stage 3: Production ───────────────────────────────────────────────────────
4854
FROM node:20-alpine AS production

0 commit comments

Comments
 (0)