Skip to content
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

Configurable esbuild #41

Open
Hejtmus opened this issue Jun 12, 2024 · 3 comments
Open

Configurable esbuild #41

Hejtmus opened this issue Jun 12, 2024 · 3 comments

Comments

@Hejtmus
Copy link

Hejtmus commented Jun 12, 2024

Hello,
I was just considering using this adapter, but my application uses top level awaits, which is only supported by esmodules. This adapter enforces commonjs, which negatively influences usability.
My suggestion is giving ability to users to override esbuild options, as majority of other adapter does.
Best regards,
Filip.

@yarbsemaj
Copy link
Owner

yarbsemaj commented Jun 12, 2024

Hi @Hejtmus
Thank You for your interest in my project!

I have published a new version (1.2.2) that adds support for this, you can now override any esbuild param, check the readme for details.

Let me know if this meets your needs 😃

Thanks James

@Hejtmus
Copy link
Author

Hejtmus commented Jun 12, 2024

Wow, that was quick, good job @yarbsemaj. Thanks for your quick reaction.

But I think there is needed one other tweak as apparently it generates cjs code for some parts of code:

Building router
▲ [WARNING] The CommonJS "exports" variable is treated as a global variable in an ECMAScript module and may not work as expecte
d [commonjs-variable-in-esm]

    build/edge/_router.js:5:0:
      5 │ exports.handler = (event, context, callback) => {
        ╵ ~~~~~~~

  This file is considered to be an ECMAScript module because the enclosing "package.json" file sets
  the type of this file to "module":

    package.json:39:12:
      39 │     "type": "module",
         ╵             ~~~~~~~~

  Node's package format requires that CommonJS files in a "type": "module" package use the ".cjs"
  file extension.

I think this is caused by second build, which doesn't apply the override.

Also I saw your usage of spread syntax, I'm not sure if that's an intention, but you can use it like this:

      esbuild.buildSync({
        entryPoints: [`${edge_directory}/_router.js`],
        outfile: `${edge_directory}/router.js`,
        format: 'cjs',
        bundle: true,
        platform: 'node',
        ...esbuildOverride
      })

@Hejtmus
Copy link
Author

Hejtmus commented Jun 13, 2024

Sorry, solution I proposed wouldn't fix the warning, as that cjs export is in router's code. For my app I manually replaced it for esm export (which does the trick), but I'm not sure how to accomplish this automatically from esbuild config.

@yarbsemaj yarbsemaj reopened this Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants