Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexer: TypeScript Module Not Found in Docker Container #2476

Open
josusanmartin opened this issue Oct 4, 2024 · 2 comments
Open

Indexer: TypeScript Module Not Found in Docker Container #2476

josusanmartin opened this issue Oct 4, 2024 · 2 comments
Labels

Comments

@josusanmartin
Copy link

josusanmartin commented Oct 4, 2024

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/[email protected]_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/util.js
...

Environment

  • Docker version: 27.2.0, build 3ab4256
  • docker-compose version: 1.29.2
  • Operating System: Ubuntu 22.04

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:

  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/[email protected] 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/[email protected]_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/util.js
postgres-package_1  | - /home/dydx/app/node_modules/.pnpm/[email protected]_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/index.js
postgres-package_1  | - /home/dydx/app/node_modules/.pnpm/[email protected]_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/[email protected][email protected]/node_modules/knex/lib/util/import-file.js
postgres-package_1  | - /home/dydx/app/node_modules/.pnpm/[email protected][email protected]/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/[email protected]_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/util.js:117:24)
postgres-package_1  |     at resolveCompiler (/home/dydx/app/node_modules/.pnpm/[email protected]_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/configuration.js:227:22)
postgres-package_1  |     at resolveAndLoadCompiler (/home/dydx/app/node_modules/.pnpm/[email protected]_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/configuration.js:220:26)
postgres-package_1  |     at findAndReadConfig (/home/dydx/app/node_modules/.pnpm/[email protected]_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/configuration.js:48:28)
postgres-package_1  |     at create (/home/dydx/app/node_modules/.pnpm/[email protected]_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/index.js:146:69)
postgres-package_1  |     at Object.register (/home/dydx/app/node_modules/.pnpm/[email protected]_2dd5d46eecda2aef953638919121af58/node_modules/ts-node/dist/index.js:127:19)
postgres-package_1  |     at Object.<anonymous> (/home/dydx/app/node_modules/.pnpm/[email protected]_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.
Copy link

linear bot commented Oct 4, 2024

@sl4mmy
Copy link

sl4mmy commented Nov 12, 2024

Ran into the same issue on a fresh clone at the indexer/v7.0.1 tag. Can also confirm the proposed solution works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants