-
Notifications
You must be signed in to change notification settings - Fork 196
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
Using ESM in external preflight function fails #3013
Comments
I wonder:
If none of the above conditions are met, the |
I tried renaming to
|
Hi, This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. |
The core issue is that wing runs preflight as CJS modules. So we This works fine inflight because we upfront bundle everything to CJS. The two main solution options:
Both of these things are good ideas regardless, (1) for possible perf and general modernization, (2) to also enable using typescript platforms and preflight externs. |
Closes #5868 (except the static part, but that's not critical for the use-case) Compiling a wing project will now generate .d.ts files for the contract between wing and extern files. These .d.ts files are fully self-contained. The code for this looks similar to existing dtsification code, but there are couple important distinctions that made it feel useful to separate it: 1. The new code only access to type information rather than the original ASTs 2. The new code is intentionally generating types in the same file as needed instead of producing references Misc: - No longer emit any files if any errors occur during compiliation - Internally change extern to use Utf8PathBuff - Converted some `examples` externs into typescript (I would love to do the rest, but need #3013) Note that this may be a breaking change: extern types must be consistent. So in one class you refer to an extern as returning a `str` and in another it returns a Json, that will now be a compiler error. *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
Fixes #3013 ~TODO~ - [x] Check benchmarks to make sure happy path perf isn't hurt - [x] Windows - [x] ~Add e2e test to verify fix for `"type": "module"`~ Doesn't fix that issue anymore - [x] Docs to officially sanction using ts in both preflight and inflight via extern *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
Congrats! 🚀 This was released in Wing 0.70.2. |
I tried this:
utils.js:
This happened:
I expected this:
It works, as it does for inflight functions (probably due to the esbuild bundling)
Is there a workaround?
use commonjs where possible
Component
Compiler
Wing Version
0.21.5
Wing Console Version
No response
Node.js Version
v18.16.0
Platform(s)
MacOS
Anything else?
Changing the file extension to
.mjs
or setting"type": "module"
doesn't change it either.Community Notes
The text was updated successfully, but these errors were encountered: