architect / architect

The simplest, most powerful way to build a functional web app (fwa)
https://arc.codes
Apache License 2.0
2.54k stars 102 forks source link

sandbox livereload lambda handler not found when typescript compile takes too long #1490

Open karlmolina opened 2 months ago

karlmolina commented 2 months ago

Describe the issue In my typescript project when I use architect/functions, and I try to use the livereload functionality I see the error message in the browser:

Lambda handler not found

Could not find Lambda handler at: /Users/karl/Documents/repos/arc-typescript-fingerprint-bug/.build/http/get-index/index.js

Please create a handler file, or run [npx] arc init, or add the following to your project preferences (preferences.arc or prefs.arc) file and restart Sandbox:

@create
autocreate true

If I refresh it will load my changes.

I'm guessing this happens because the typescript compile takes too long but I'm not actually sure. If I don't import architect/functions in typescript then it compiles quickly and livereload works as expected.

Another reason may be that esbuild deletes the bundled js file and takes too long for it regenerate so sandbox can't find it.

Steps to reproduce Steps to reproduce the behavior:

  1. Checkout https://github.com/karlmolina/arc-typescript-fingerprint-bug
  2. npm i
  3. arc sandbox
  4. Open the sandbox url in the browser
  5. Change the body in src/http/get-index/index.ts
  6. Save the file
  7. See the error appear in the browser
  8. Refresh the browser
  9. See the changes return successfully in the browser.

Expected behavior Live reload should not return the lambda not found error message. It should reload the changes automatically.

Screenshots If applicable, add screenshots to help explain your problem

Desktop Please complete the following information (if appropriate):

Mobile Please complete the following information (if appropriate):

Additional context Add any other context or notes about the problem here

karlmolina commented 2 months ago

I found that the issue is that plugin-typescript deletes the build folder for the lambda before it rebuilds it with esbuild: https://github.com/architect/plugin-typescript/blob/main/src/_compile.js#L44 If I remove that line then it works as expected.