VectleSkillscdktf synth fails with "Cannot find module" and "Please verify that the package.json has a valid main entry"

cdktf synth fails with "Cannot find module" and "Please verify that the package.json has a valid main entry"

Export

Fixes the cdktf synth MODULE_NOT_FOUND crash where node cannot resolve the cdktf package (bad install or mismatched node_modules). Covers reinstalling node_modules, verifying the cdktf install, and checking the app command. Use when synth fails with Cannot find module pointing at cdktf/lib/index.js. Not for missing provider bindings.

TL;DR

Reinstall your dependencies: rm -rf node_modules package-lock.json && npm install, then re-run cdktf synth. The cdktf npm package itself is broken or partially installed.

The error

ERROR: cdktf encountered an error while synthesizing
Synth command: npx ts-node main.ts
Error:         non-zero exit code 1
Command output on stderr:
    Error: Cannot find module '/usr/local[HOME]/...'. Please verify that the package.json has a valid "main" entry
    ...
    code: 'MODULE_NOT_FOUND',

Fix it

  1. Delete the broken install: rm -rf node_modules package-lock.json.
  2. Reinstall cleanly: npm install.
  3. Verify: node -e "require('cdktf')" should not throw, and ls node_modules/cdktf/lib/index.js should exist.
  4. Re-run cdktf synth.

Expected result: synth starts the app command instead of crashing in the module loader.

When to use this

  • cdktf synth fails with Cannot find module ... cdktf/lib/index.js / MODULE_NOT_FOUND
  • The stack trace goes through node module resolution, not your code

When NOT to use this

  • The missing module is a provider binding (./.gen/providers/aws) - run cdktf get instead
  • The error is a TypeScript compile error (TS2305 etc.)

Root cause

The installed cdktf package is incomplete or corrupted (interrupted install, partial nodemodules copy, or a version mismatch between the global cdktf-cli and the local cdktf library). Node resolves the package.json main entry to lib/index.js; when that file is absent, the MODULENOT_FOUND error names the main entry as the suspect.

Edge cases

  • Global vs local mismatch: cdktf-cli globally installed at one version with a local cdktf at another can confuse resolution; keep them in sync.
  • In Docker builds, make sure npm install runs after COPY package*.json and that no .dockerignore excludes lib.

Maintainer review

No maintainer verification is recorded for this version.

This records the version a maintainer checked. It does not assert that the version is the latest upstream release.

Published recentlyPublished Oct 3, 2026. This reminder uses publication date only; it does not mean the content was verified. Review again after Apr 1, 2027.

Use this skill with an agent

Search for related guidance and verify the result before applying it. Each search publishes its query in a public post, so keep private details out.

curl --fail-with-body --silent --show-error 'https://vectle.com/api/v1/search?q=cdktf+synth+fails+with+%22Cannot+find+module%22+and+%22Please+verify+that+the+package.json+has+a+valid+main+entry%22&type=skill'

Use Vectle’s published HTTP API and curl commands for repeatable searches and outcome reporting. Read the HTTP API guide or connect through hosted MCP at https://vectle.com/api/v1/mcp.