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

Error: Cannot find module '@cdktf/provider-aws' #244

Closed
Chriscbr opened this issue Oct 10, 2022 · 3 comments · Fixed by #245 or #250
Closed

Error: Cannot find module '@cdktf/provider-aws' #244

Chriscbr opened this issue Oct 10, 2022 · 3 comments · Fixed by #245 or #250
Labels
🐛 bug Something isn't working ⌨️ cli CLI

Comments

@Chriscbr
Copy link
Contributor

Chriscbr commented Oct 10, 2022

I ran wing compile hello.w using the latest @monadahq/wing with:

// hello.w
bring cloud;

And got

Error: Cannot find module '@cdktf/provider-aws'

It looks like the issue is @monadahq/wing takes @monadahq/wingsdk as a bundled dependency, but @monadahq/wingsdk has several peer dependencies so they aren't automatically bundled.

@Chriscbr
Copy link
Contributor Author

Now getting the error Error: Cannot find module 'esbuild-wasm' - investigating...

@Chriscbr
Copy link
Contributor Author

I think the root cause might be this bug: npm/cli#3466

When I install @monadahq/wingsdk from a fresh new project, esbuild-wasm is included (it's one of the bundledDependencies) -- but when @monadahq/wingsdk is tagged as a bundledDependency of @monadahq/wing, esbuild-wasm gets totally lost. I can verify this by running npm pack inside the directory and checking the tarball that's produced.

Maybe "manually" bundling the SDK using a tool like esbuild is needed after all. Another option could be to manually bundle dependencies inside the SDK package

@Chriscbr
Copy link
Contributor Author

Chriscbr commented Oct 10, 2022

Oh, huh - I didn't see that coming. So, trying to esbuild the SDK introduces some new problems, because right now the SDK does some hacky file path mangling in order to reference inflight functions. See here: https://github.com/monadahq/winglang/blob/e105b2d3b7f91a3eec9d07aa47662c7550b06220/libs/wingsdk/src/core/inflight.ts#L304-L316

I suspect that's actually a bit of a code smell though, so it's probably worth fixing.

edit: full logs for context:

../winglang/apps/wing/bin/wing compile hello.w
Skipping unimplemented type check
Skipping unimplemented type check
Skipping unimplemented type check
Skipping unimplemented type check
const $stdlib = require("@monadahq/wing").sdk;
const $outdir = process.env.WINGSDK_SYNTH_DIR ?? ".";
const $synthesizer = process.env.WING_SIM ? new $stdlib.sim.Synthesizer({ outdir: $outdir }) : new $stdlib.tfaws.Synthesizer({ outdir: $outdir });
const cloud = require("@monadahq/wing").sdk.cloud;
class MyApp extends $stdlib.core.App {
constructor() {
  super({ synthesizer: $synthesizer });

  let bucket = new cloud.Bucket(this.root,"cloud.Bucket");
  const handler = new $stdlib.core.Inflight({
    code: $stdlib.core.NodeJsCode.fromFile("proc.62a8fd6a6e6cef2d42d4eb7dacfe2c33547c24b1bc5ffafc9ce91ee324e7c327/index.js"),
    entrypoint: "$proc",
    captures: {
      bucket: {
        resource: bucket,
        methods: ["put"]
      },
    }
  });
  new cloud.Function(this.root,"cloud.Function",handler)
}
}
new MyApp().synth();
/Users/chrisr/dev/winglang/apps/wing
node:internal/modules/cjs/loader:958
  throw err;
  ^

Error: Cannot find module '/Users/chrisr/dev/winglang/apps/wing/dist/index.inflight'
Require stack:
- /Users/chrisr/dev/winglang/apps/wing/dist/index.js
- /Users/chrisr/dev/wing-test/hello.w.out/intermediate.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:955:15)
    at Function.resolve (node:internal/modules/cjs/helpers:109:19)
    at InflightClient.for (/Users/chrisr/dev/winglang/apps/wing/dist/index.js:711630:63)
    at Bucket._capture (/Users/chrisr/dev/winglang/apps/wing/dist/index.js:712086:41)
    at createClient (/Users/chrisr/dev/winglang/apps/wing/dist/index.js:711619:33)
    at Inflight.makeClients (/Users/chrisr/dev/winglang/apps/wing/dist/index.js:711608:27)
    at new Function (/Users/chrisr/dev/winglang/apps/wing/dist/index.js:711899:41)
    at PolyconFactory.resolve (/Users/chrisr/dev/winglang/apps/wing/dist/index.js:712198:20)
    at Polycons.newInstance (/Users/chrisr/dev/winglang/apps/wing/dist/index.js:709018:24)
    at new Function (/Users/chrisr/dev/winglang/apps/wing/dist/index.js:711783:36) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/chrisr/dev/winglang/apps/wing/dist/index.js',
    '/Users/chrisr/dev/wing-test/hello.w.out/intermediate.js'
  ]
}

Node.js v18.9.0

skyrpex added a commit that referenced this issue Jun 21, 2023
Fixes #244

Co-authored-by: Cristian Pallarés <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working ⌨️ cli CLI
Projects
None yet
1 participant