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

ESM plugins do not work with begin dev #154

Open
ryanbethel opened this issue Jun 22, 2023 · 10 comments
Open

ESM plugins do not work with begin dev #154

ryanbethel opened this issue Jun 22, 2023 · 10 comments

Comments

@ryanbethel
Copy link
Contributor

ESM plugins don't work with the Begin CLI using begin dev. They do, however, work when using sandbox directly.

Steps to reproduce:
Using @brianleroux 's S3 upload repo at https://github.com/brianleroux/enhance-example-s3-upload .

  1. clone the repo git clone https://github.com/brianleroux/enhance-example-s3-upload.git
  2. install deps npm i
  3. run begin dev
  4. install sandbox npm i @architect/sandbox
  5. run sandbox npx sandbox

You should see the following error when running begin dev but no error running npx sandbox:

Error: Plugin error:
- Unable to load plugin 's3': Invalid host defined options
    at getPluginModules (/snapshot/cli/node_modules/@architect/inventory/src/config/pragmas/plugins.js)
    at getPluginModulesCallbackified (node:util:306:5)
    at architectInventory (/snapshot/cli/node_modules/@architect/inventory/src/index.js)
    at action (/snapshot/cli/src/commands/dev/index.js)
    at runCommand (/snapshot/cli/src/commands/index.js)
    at begin (/snapshot/cli/src/index.js)
    at Object.<anonymous> (/snapshot/cli/src/index.js)
    at Module._compile (pkg/prelude/bootstrap.js:1926:22)
    at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
➜  enhance-example-s3-upload git:(main) ✗
@ryanblock
Copy link
Member

Under the hood it is just an import statement. As such, paths need to include file names.

@brianleroux
Copy link
Member

Let's document this

@ryanbethel
Copy link
Contributor Author

ryanbethel commented Jun 22, 2023

It still fails with a full filename for begin dev, but it works for sandbox. I think this is a bug in the CLI. If you change the arc file plugin call to :

@app
begin-app

@static
prune true

@plugins
enhance/arc-plugin-enhance
enhance/styles-cribsheet
s3
  src plugins/s3/index.js

You get the same error.

@ryanblock
Copy link
Member

Uh oh: https://stackoverflow.com/questions/69734757/dynamic-import-import-fails-when-the-code-is-packaged-into-an-executable

Okay, for some reason node executables made with package pkg doesn't honor import() statements.

@ryanblock
Copy link
Member

See also: vercel/pkg#1291

@brianleroux
Copy link
Member

What a nightmare.

@ryanblock
Copy link
Member

Indeed, apologies for the early closure of the issue @ryanbethel, Brian and I had worked through another esm plugin issue (the file name) from this repo already, I assumed it was the same.

So I think the answer here for now is: Begin CLI currently does not support ESM plugins (due to limitations in pkg). Thoughts?

@macdonst
Copy link
Member

It's frustrating that we are in a situation with pkg that begin dev does not have parity with arc sandbox. From a DX perspective, I'd expect this to "just work" in begin dev. We already have an issue explaining the difference between Architect, Enhance and Begin and this further confuses things.

Note: this is me being frustrated with pkg.

@brianleroux
Copy link
Member

its a deep sunk cost discussion but i feel like we should embrace npm i -g @begin/cli and walk on this approach for now

@ryanblock
Copy link
Member

Added better error handling when ESM plugins fail in pkg-compiled binary distributions; it's not a real fix, but it's at least a bit less bewildering!

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

4 participants