When trying to deploy the dYdX v4 Indexer in a Docker container, the postgres-package service fails to start due to a "Cannot find module 'typescript'" error. This occurs despite TypeScript being installed locally.
Steps to Reproduce
Clone the dYdX v4 Indexer repository
Run pnpm install to install dependencies
Build the Docker images using docker-compose -f docker-compose-local-deployment.yml build
Attempt to start the services using docker-compose -f docker-compose-local-deployment.yml up
Expected Behavior
All services, including the postgres-package service, should start successfully.
Actual Behavior
The postgres-package service fails to start, producing the following error:
The TypeScript module was not being properly installed or recognized within the Docker container environment. The Dockerfile did not explicitly install TypeScript and ts-node for the workspace root.
Solution
Update the Dockerfile.postgres-package.local with the following changes:
Add TypeScript and ts-node installation to the workspace root:
RUN pnpm add -w typescript@4.7.4 ts-node@10.9.1
Update the PATH to include the node_modules/.bin directory:
ENV PATH=/home/dydx/app/node_modules/.bin:$PATH
After making these changes, rebuild the Docker image and run the containers again.
Logs
This is the output from the Docker log docker-compose -f docker-compose-local-deployment.yml logs
postgres-package_1 |
postgres-package_1 | > @dydxprotocol-indexer/postgres@0.0.1 migrate /home/dydx/app/packages/postgres
postgres-package_1 | > knex migrate:latest
postgres-package_1 |
postgres-package_1 | Error: Cannot find module 'typescript'
postgres-package_1 | Require stack:
postgres-package_1 | - /home/dydx/app/node_modules/.pnpm/ts-node@10.8.2_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/util.js
postgres-package_1 | - /home/dydx/app/node_modules/.pnpm/ts-node@10.8.2_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/index.js
postgres-package_1 | - /home/dydx/app/node_modules/.pnpm/ts-node@10.8.2_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/register/index.js
postgres-package_1 | - /home/dydx/app/packages/postgres/knexfile.js
postgres-package_1 | - /home/dydx/app/node_modules/.pnpm/knex@0.21.21_pg@8.7.3/node_modules/knex/lib/util/import-file.js
postgres-package_1 | - /home/dydx/app/node_modules/.pnpm/knex@0.21.21_pg@8.7.3/node_modules/knex/bin/cli.js
postgres-package_1 | at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
postgres-package_1 | at Function.resolve (node:internal/modules/cjs/helpers:108:19)
postgres-package_1 | at projectLocalResolveHelper (/home/dydx/app/node_modules/.pnpm/ts-node@10.8.2_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/util.js:117:24)
postgres-package_1 | at resolveCompiler (/home/dydx/app/node_modules/.pnpm/ts-node@10.8.2_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/configuration.js:227:22)
postgres-package_1 | at resolveAndLoadCompiler (/home/dydx/app/node_modules/.pnpm/ts-node@10.8.2_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/configuration.js:220:26)
postgres-package_1 | at findAndReadConfig (/home/dydx/app/node_modules/.pnpm/ts-node@10.8.2_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/configuration.js:48:28)
postgres-package_1 | at create (/home/dydx/app/node_modules/.pnpm/ts-node@10.8.2_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/index.js:146:69)
postgres-package_1 | at Object.register (/home/dydx/app/node_modules/.pnpm/ts-node@10.8.2_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/index.js:127:19)
postgres-package_1 | at Object.<anonymous> (/home/dydx/app/node_modules/.pnpm/ts-node@10.8.2_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/register/index.js:1:16)
postgres-package_1 | at Module._compile (node:internal/modules/cjs/loader:1105:14)
postgres-package_1 | ELIFECYCLE Command failed with exit code 1.
Additional Notes
The TypeScript version 4.7.4 is specified as it matches the version referenced in the project's package.json.
This fix assumes that the project is using a workspace setup with pnpm. If the project structure changes, the solution may need to be adjusted accordingly.
Description
When trying to deploy the dYdX v4 Indexer in a Docker container, the postgres-package service fails to start due to a "Cannot find module 'typescript'" error. This occurs despite TypeScript being installed locally.
Steps to Reproduce
pnpm install
to install dependenciesdocker-compose -f docker-compose-local-deployment.yml build
docker-compose -f docker-compose-local-deployment.yml up
Expected Behavior
All services, including the postgres-package service, should start successfully.
Actual Behavior
The postgres-package service fails to start, producing the following error:
Environment
Root Cause
The TypeScript module was not being properly installed or recognized within the Docker container environment. The Dockerfile did not explicitly install TypeScript and ts-node for the workspace root.
Solution
Update the Dockerfile.postgres-package.local with the following changes:
Add TypeScript and ts-node installation to the workspace root:
Update the PATH to include the node_modules/.bin directory:
After making these changes, rebuild the Docker image and run the containers again.
Logs
This is the output from the Docker log
docker-compose -f docker-compose-local-deployment.yml logs
Additional Notes