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

support ES module importing #43

Open
ojanvafai opened this issue Jan 8, 2019 · 2 comments
Open

support ES module importing #43

ojanvafai opened this issue Jan 8, 2019 · 2 comments

Comments

@ojanvafai
Copy link

I'd love to be able to use this library directly out of node_modules, but it doesn't work with ES modules.

Ideally it would export native ES Modules, but I'd also be fine with just loading it for side effects. The only problem is that "this" is undefined in ES Modules. Changing the last line from "}(this));" to "}(self));" makes that possible.

@jackbearheart
Copy link
Owner

I see. I'm not sure if this is a problem or not and under what circumstances. I also don't want to break anything by messing with module loading, since people interact with this code in different contexts.

What module loader are you using? This works for me:

➜  proj ls
main.js  node_modules  package.json  package-lock.json
➜  proj cat package.json
{
  "name": "proj",
  "type": "module",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "email-addresses": "^3.1.0"
  }
}
➜  proj cat main.js

import addrs from 'email-addresses';

console.log(addrs.parseOneAddress('foo@example.com').domain);
➜  proj node --version
v14.11.0
➜  proj node main.js
example.com

@ojanvafai
Copy link
Author

I'm loading it directly in Chrome. I didn't end up using this library, I don't have the test case around still. But I would expect the following to hit it:

<script type=module src="email-addresses.js"></script>

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