deno-lambda icon indicating copy to clipboard operation
deno-lambda copied to clipboard

import_map causes module not found

Open kyeotic opened this issue 3 years ago • 4 comments
trafficstars

I have an otherwise working application that fails if I try to use an import map; specifically the kind of import maps generated by trex. I have created a minimal repro of the issue with this repository. Here is the working version without the import map.

The failure it produces is

2022-05-30T13:22:56.089-07:00 | error: Module not found "file:///var/task/tmp/runtime.js".
-- | --
  | 2022-05-30T13:22:56.133-07:00 | error: deno exited
  | 2022-05-30T13:22:56.219-07:00 | START RequestId: ee82b3a3-6dc4-4f7b-ae89-d7646649862d Version: $LATEST
  | 2022-05-30T13:22:56.822-07:00 | error: Module not found "file:///var/task/tmp/runtime.js".
  | 2022-05-30T13:22:57.303-07:00 | error: deno exited
  | 2022-05-30T13:22:57.443-07:00 | END RequestId: ee82b3a3-6dc4-4f7b-ae89-d7646649862d
  | 2022-05-30T13:22:57.443-07:00 | REPORT RequestId: ee82b3a3-6dc4-4f7b-ae89-d7646649862d Duration: 1222.96 ms Billed Duration: 1223 ms Memory Size: 128 MB Max Memory Used: 12 MB
  | 2022-05-30T13:22:57.443-07:00 | Unknown application error occurred Unhandled
  | 2022-05-30T13:22:57.904-07:00 | error: Module not found "file:///var/task/tmp/runtime.js".
  | 2022-05-30T13:22:57.945-07:00 | error: deno exited

kyeotic avatar May 30 '22 20:05 kyeotic

Thanks, I haven't really used terraform so this is interesting! Could you share the steps how you generated these files? or did you create them all?


That error is definitely bad. 🤔

Some thoughts from reading the scripts:

Can you remove the /dev/nulls from this file and see if there is any helpful output? https://github.com/kyeotic/deno-lambda-repro/blob/main/scripts/bundle_lambda#L14-L32

Also, potentially worth trying the bundle method/line instead?

hayd avatar May 30 '22 21:05 hayd

The dev/null pipes just hide all the individual file noise. You can comment them out and see no errors are being hidden. Again, this exact setup works without the import map; just replace the import with one directly to the url (or check out the working-deps branch and deploy that).

You have to have terraform installed to use these, but the deploy step is simply

// from the project root folder
./scripts/deploy dev // (or whatever)

You can run bundle_lambda on its own if you just want to see the zip it produces, but deploy will run that on its own. As far as how they were generated... I've been using terraform for a while, they've been copied and developed over a few years. The core "deno lambda" bundling logic came from this repo though, its nothing special except for the additional of the import map.

kyeotic avatar May 30 '22 23:05 kyeotic

Related from #176:

The failure to transform DENO_IMPORTMAP = "./import_map.json" the way $LAMBDA_TASK_ROOT/$HANDLER_FILE is possibly a bug, but I don't think it is related.

hayd avatar May 30 '22 23:05 hayd

The fix may possibly be to add a mapping of $LAMBDA_TASK_ROOT as a redirect to ./ in import_map.json, possibly? Can definitely confirm this is reproduceable with an empty zip file and a lambda function that is baked with the provided Deno runtime. Removing the import_map from the env var actually remedies the problem.

Bundling works around this problem for now.

gm112 avatar Jul 29 '22 05:07 gm112