JakeChampion/polyfill-library

FEATURE: Add a script to copy Polyfills to distribution folder

RodrigoTomeES opened this issue · 3 comments

Hello,

Recently, we attempted to implement an endpoint in NextJS to serve client-based polyfills. During local testing, it worked perfectly, even with the production build. However, upon deployment to the development environment, the API encountered an error indicating that it couldn't locate the polyfills.

As a result, we opened issue #1219 to address this problem. With the assistance of @JakeChampion, we were able to find a solution. To resolve the issue, we need to include the polyfills in our final bundle and modify the plugin's access path for reading the polyfills, thereby creating a package path. Consequently, I propose the following two changes:

  • Store the distribution polyfills in a relative path instead of /var/... to avoid potential issues in environments where that path is inaccessible (e.g., in a lambda function).
  • Provide a script that copies the polyfills to the distribution build, similar to the functionality offered by partytown.

Implementing these changes will greatly simplify the process of using the library when generating a bundle.

Thank you and best regards!


The framework used is NextJS and it's deployed to AWS Lambda with Serverless NextJS.

Thanks for the thorough issue, this is great! I think you may be the first using polyfill-library in aws lambda and also as a NextJS route

Store the distribution polyfills in a relative path instead of /var/... to avoid potential issues in environments where that path is inaccessible (e.g., in a lambda function).

I don't believe polyfill-library stores anything in /var/ - I'm not sure what is doing that, I presume it is the NextJS' bundling mechanism because all the distribution polyfills are in ./node_modules/polyfill-library/polyfills/__dist/, which you should hopefully see on this page https://unpkg.com/browse/polyfill-library@3.111.0/polyfills/__dist/

@JakeChampion I don't think is a problem with NextJS bundling because if we build a production NextJS without Serverless it's works so maybe the problem is that but in the Serverless bundling.

I update the README to reflect the problem with routes in AWS Lambda because this is not a library issue but it's without documentation #1291