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

ERR_REQUIRE_ESM: The simplest fix! #897

Open
michaelfig opened this issue May 23, 2021 · 9 comments
Open

ERR_REQUIRE_ESM: The simplest fix! #897

michaelfig opened this issue May 23, 2021 · 9 comments

Comments

@michaelfig
Copy link
Contributor

michaelfig commented May 23, 2021

The simplest way I could find to fix #868 was to publish a fork.

Please take a look at https://github.com/agoric-labs/esm/tree/Agoric#readme

@Venryx
Copy link

Venryx commented Jun 22, 2021

Didn't work for me; not sure why.

I installed the modified esm package using Yarn 2: (note that the instructions in your readme don't work for Yarn 2; I had to add esm@ to the start, as instructed here)

yarn add -D esm@https://github.com/agoric-labs/esm.git#Agoric-built

I added this as my launch script:

node -r esm ./dist/index.js

However, when I run that script, it still gives the same error as the regular esm:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\...\dist\index.js
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1217:13) {
  code: 'ERR_REQUIRE_ESM'
}

If I find further info, I'll post it here.

@Venryx
Copy link

Venryx commented Jun 22, 2021

Oh, it looks like Node 14.13.0+ supports named imports from common-js modules!: https://simonplend.com/node-js-now-supports-named-imports-from-commonjs-modules-but-what-does-that-mean

Well, some of them anyway. (the blog post linked shows how it only works for some packages -- ones where cjs-module-lexer is able to detect the export names through static analysis)

There may not be a need for these sorts of workarounds soon then. (I'll have to see, after using Node 14.13.0+ for a while)

@motss
Copy link

motss commented Jul 4, 2021

@michaelfig Thanks for the simple fix. I also found out that the fix itself is not enough, at least for my case. I have to override the esm config with the following config:

/** package.json */
{
  ...
  "esm": {
    "cjs": true,
    "mode": "all"
  }
}

@mashpie
Copy link

mashpie commented Jan 6, 2022

@michaelfig any plans to release your fix to npm or get this merged into esm?

It's providing exactly what I wanted: Authoring ESM modules by default with .js extentension. Use a index.cjs as entry for require() - perfect upgrade path imho. Thanks a lot!

@michaelfig
Copy link
Contributor Author

@michaelfig any plans to release your fix to npm or get this merged into esm?

Doesn't seem so. I think this upstream esm repo has been abandoned.

Also, instead of putting on NPM (where it would need to have a different name), just follow the instructions at the top of the readme linked in the description to install from Github.

Thanks a lot!

My pleasure!

@mk-pmb
Copy link
Contributor

mk-pmb commented Mar 23, 2022

@michaelfig
Do you still maintain the agoric fork? I get lots of deprecation warnings and, more importantly, a test failure. I posted them there because the agoric repo has its issue tracker disabled. Would you nonetheless be willing to debug them?

@michaelfig
Copy link
Contributor Author

@michaelfig Do you still maintain the agoric fork? I get lots of deprecation warnings and, more importantly, a test failure. I posted them there because the agoric repo has its issue tracker disabled. Would you nonetheless be willing to debug them?

Sorry, I don't need this package anymore as Agoric has completed its migration off of it, and other priorities beckon.

I hate to contribute to more abandonware, but here I am.

@mk-pmb
Copy link
Contributor

mk-pmb commented Mar 23, 2022

Ok then. Could you explain that in your README then? Thanks!

@mk-pmb
Copy link
Contributor

mk-pmb commented Mar 23, 2022

@mashpie or anyone else who'd prefer to install it from npm rather than GitHub: https://www.npmjs.com/package/agoric-labs-esm-built-pmb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants