aws / aws-pdk

The AWS PDK provides building blocks for common patterns together with development tools to manage and build your projects.
https://aws.github.io/aws-pdk/
Apache License 2.0
384 stars 75 forks source link

[BUG] Python pdk command "Cannot find module '../lib/cli.js'" #667

Closed jstrunk closed 6 months ago

jstrunk commented 11 months ago

Describe the bug

When running pdk on a Python monorepo in CodeBuild, I get the error "Cannot find module '../lib/cli.js'".

I’m using feature branch pipelines It happens in CodeBuild in a new branch that worked fine on my local machine. New branches cloned from main continue to work. There are new projects in the .projenrc.py, and some package versions are different. I confirmed that builds from main work with both pdk 0.22.42 and 0.22.44. In troubleshooting, I determined that the pdk command being run in CodeBuild is the one installed by poetry. On my local machine, it also runs the pdk installed by poetry. There’s no difference in yarn.lock.

Expected Behavior

I expect pdk to run successfully.

Current Behavior

Error message from build logs

[Container] 2023/12/07 03:53:40.135114 Running command pdk node:internal/modules/cjs/loader:1080 throw err; ^

Error: Cannot find module '../lib/cli.js' Require stack:

  • /usr/local/bin/npx at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15) at Module._load (node:internal/modules/cjs/loader:922:27) at Module.require (node:internal/modules/cjs/loader:1143:19) at require (node:internal/modules/cjs/helpers:110:18) at Object. (/usr/local/bin/npx:3:13) at Module._compile (node:internal/modules/cjs/loader:1256:14) at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Module._load (node:internal/modules/cjs/loader:960:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) { code: 'MODULE_NOT_FOUND', requireStack: [ '/usr/local/bin/npx' ] }

Node.js v18.16.1 /root/.cache/aws/jsii/package-cache/@aws/pdk/0.22.44/b9ff9bc92ed9b2038305d406e30c6eb93052224ec3575227a439922f1b343ae4/node_modules/execa/index.js:212 throw error; ^

Error: Command failed with exit code 1: npx projen at makeError (/root/.cache/aws/jsii/package-cache/@aws/pdk/0.22.44/b9ff9bc92ed9b2038305d406e30c6eb93052224ec3575227a439922f1b343ae4/node_modules/execa/lib/error.js:60:11) at module.exports.sync (/root/.cache/aws/jsii/package-cache/@aws/pdk/0.22.44/b9ff9bc92ed9b2038305d406e30c6eb93052224ec3575227a439922f1b343ae4/node_modules/execa/index.js:194:17) at module.exports.commandSync (/root/.cache/aws/jsii/package-cache/@aws/pdk/0.22.44/b9ff9bc92ed9b2038305d406e30c6eb93052224ec3575227a439922f1b343ae4/node_modules/execa/index.js:235:15) at Object. (/root/.cache/aws/jsii/package-cache/@aws/pdk/0.22.44/b9ff9bc92ed9b2038305d406e30c6eb93052224ec3575227a439922f1b343ae4/_scripts/exec-command.js:39:9) at Module._compile (node:internal/modules/cjs/loader:1256:14) at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Module._load (node:internal/modules/cjs/loader:960:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:23:47 { shortMessage: 'Command failed with exit code 1: npx projen', command: 'npx projen', escapedCommand: 'npx projen', exitCode: 1, signal: undefined, signalDescription: undefined, stdout: undefined, stderr: undefined, failed: true, timedOut: false, isCanceled: false, killed: false }

Node.js v18.16.1

[Container] 2023/12/07 03:54:08.806627 Command did not exit successfully pdk exit status 1

Reproduction Steps

buildspec

version: "0.2"
phases:
  install:
    commands:
      - npm install -g aws-cdk @aws/pdk
      - python3 -m venv .venv
      - . ./.venv/bin/activate
      - pip install poetry
      - poetry install --no-root
      - pdk
  build:
    commands:
      - pdk build
      - cd packages/infra
      - cdk synth
      - cdk deploy --require-approval=never
artifacts:
  files:
    - "**/*"

Possible Solution

No response

Additional Information/Context

No response

PDK version used

0.22.44

What languages are you seeing this issue on?

Python

Environment details (OS name and version, etc.)

CodeBuild STANDARD_7_0

jstrunk commented 11 months ago

As a workaround, running npx pdk in the buildspec seems to run the globally installed version, and the build succeeds.

dbryson commented 10 months ago

When I have had this problem I have removed node_modules and package-lock.json. Then run npx install and the error seems to go away.

github-actions[bot] commented 8 months ago

This issue is now marked as stale because it hasn't seen activity for a while. Add a comment or it will be closed soon. If you wish to exclude this issue from being marked as stale, add the "backlog" label.

agdimech commented 7 months ago

Hi - is this still an issue as i've tried to reproduce with no luck :(

agdimech commented 6 months ago

This is resolved in https://github.com/aws/aws-pdk/commit/62f9229f58b0bb7e0ce12c67c9a643168bd3ecaa