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

Node.js ERR_REQUIRE_ESM with v3 #256

Closed
guillaumewuip opened this issue Aug 29, 2022 · 3 comments · Fixed by #257
Closed

Node.js ERR_REQUIRE_ESM with v3 #256

guillaumewuip opened this issue Aug 29, 2022 · 3 comments · Fixed by #257

Comments

@guillaumewuip
Copy link

Hello!

Migrating to web-vitals v3, I have an issue with the lib used in a commonjs build run by Node.js.

The big picture for (simplified to remove the browser build part):

app <-- built to commonjs to be run in Node.js
  │
  +--- imports --- lib A <-- built to commonjs 
                    |
                    +----  imports --- web-vitals v3

When I run the app in Node.js, I get this error

Error [ERR_REQUIRE_ESM]: require() of ES Module .../libA/dist/commonjs/index.js not supported.
web-vitals.umd.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename web-vitals.umd.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in .../node_modules/web-vitals/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

Removing the type: module from web-vitals package.json indeed resolves the issue.

@tizmagik
Copy link

Thanks for creating the issue, I just hit this as well.

@philipwalton
Copy link
Member

Thanks for reporting. I believe this should be fixed in v3.0.1, let me know if you're still experiencing issues.

@brmendez
Copy link

Thanks for reporting. I believe this should be fixed in v3.0.1, let me know if you're still experiencing issues.

@philipwalton thanks for the reply. I was experiencing the above issues as well. I have upgraded to v3.0.1 and am now getting this error:

ReferenceError: addEventListener is not defined
      at l (node_modules/web-vitals/dist/web-vitals.umd.cjs:1:1249)
      at h (node_modules/web-vitals/dist/web-vitals.umd.cjs:1:1649)
      at g (node_modules/web-vitals/dist/web-vitals.umd.cjs:1:1725)
      at y (node_modules/web-vitals/dist/web-vitals.umd.cjs:1:1865)

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

Successfully merging a pull request may close this issue.

4 participants