dydxprotocol / v4-chain

dydx v4 protocol
Other
229 stars 105 forks source link

Indexer: TypeScript Module Not Found in Docker Container #2476

Open josusanmartin opened 1 month ago

josusanmartin commented 1 month ago

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

  1. Clone the dYdX v4 Indexer repository
  2. Run pnpm install to install dependencies
  3. Build the Docker images using docker-compose -f docker-compose-local-deployment.yml build
  4. 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:

Error: Cannot find module 'typescript'
Require stack:
- /home/dydx/app/node_modules/.pnpm/ts-node@10.8.2_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/util.js
...

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:

  1. Add TypeScript and ts-node installation to the workspace root:

    RUN pnpm add -w typescript@4.7.4 ts-node@10.9.1
  2. 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

linear[bot] commented 1 month ago

GH-72 Indexer: TypeScript Module Not Found in Docker Container