sindresorhus / email-regex

Regular expression for matching email addresses
MIT License
134 stars 17 forks source link

Next.js import error #11

Closed maccman closed 3 years ago

maccman commented 3 years ago

Getting this when trying to use email-regex:


Error: Must use import to load ES Module: /Users/alex/repos/reflect/node_modules/email-regex/index.js
require() of ES modules is not supported.
require() of /Users/alex/repos/reflect/node_modules/email-regex/index.js from /Users/alex/repos/reflect/node_modules/@team-reflect/reflect-editor/dist/extensions/contact-extension/options.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/alex/repos/reflect/node_modules/email-regex/package.json.```
sindresorhus commented 3 years ago

This package is ESM, but Next.js still doesn't support ESM.

There's a workaround, but in this case, you can just use v4 instead, which is functionally the same, just not ESM.