-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Bug?]: PNP with ESM using Lambda Layers is broken with AWS SAM #6604
Comments
EDIT: The following may be related to #5951 in handing back an empty source, but it seems intended to hand back an empty source to get picked back up from node's ESM CJS wrapper which should then go back into the Updated the example loader to load CJS source as well; still broken if the CJS file has a require. There seem to be some heavy caveats from Node.JS on how the loader should work for CJS: There also was discussion around challenges mixing CJS And ESM loader and registration here: The thread shows as resolved -- but -- I don't think the registration applies when the entry-point is ESM. It seems null and monkey patch should work, but are not, which may be related to how AWS SAM is loading things up... But that said, when providing source, resolve and other hooks should work, but perhaps they need register. The
Unfortunately that was a temporary solution, as some CJS packages will have |
Ok this could have some redundancy, but I'm tired - so edits later: This is using:
Note -- the prepend has little to do with Yarn Berry and everything to do with getting in front of the AWS SAM loader. Here is loader.mjs
|
Self-service
Describe the bug
This is very specific to AWS SAM images - there may be some yarn bugs its uncovering, but to date this only comes up in a SAM image.
As far as I can tell, AWS has expressed negative interest in Yarn PNP and further they have their own
/var/runtime/index.mjs
wrapper which complicates things.While the .pnp.cjs file works well in AWS SAM, the ESM loader does not seem to work as desired when the loader or dependencies are outside of the project folder. Configuration variables such as the yarn cache folder are not used and it uses the current cwd, making it difficult to point to a .cjs file (which the .mjs loader uses).
Here is the fix I'm using - as the dependencies are in
/opt/nodejs/
-e-g- ".yarn" for the cache folder and family, and ".pnp.cjs" for the cjs file which is used by the.pnp.loader.mjs
file.loader.mjs:
To reproduce
Launch an ESM project putting the Yarn cache folder into a Layer Zip.
This will wind up in
/opt/nodejs/.yarn
.The ESM Loader will not work well with the
/opt/nodejs
folder as it is run from/var/task
regardless of location. It may have a struggling finding the/opt/nodejs/.pnp.cjs
file - which instead has to go into/var/task
- but working around from that, the folder search path will still look in/var/task/.yarn
and not/opt/nodejs/.yarn
despite every attempt I could muster.It's odd that yarn is not using any of the configuration variables for the
.pnp.loader.mjs
but with such a strict environment it's relatively unimportant as long as things just work.Note in the exact same setup, the ".pnp.cjs" registration does work well for ".cjs" files.
Environment
Additional context
No response
The text was updated successfully, but these errors were encountered: