-
Notifications
You must be signed in to change notification settings - Fork 32
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
Export the library as a CommonJS module #9
Comments
Another solution is to add |
Just to be clear I am using this in my Next.js app and I had to use additional plugins as NextJS doesn't support |
I originally implemented it as CommonJS, but since node 10, I'm done with babel transpiling and have converted all my projects to newer style. Just import esm before this module and it will work. My initial index files just import esm and jump to another module with imports. That way when node 14 comes along, I only have one file to touch to remove esm. With node 14.17, I've read that import is finally going to be supported. |
I've added type to the package.json. |
I am using node 16. I get the error "SyntaxError: Cannot use import statement outside a module". If I set "type": "module" in my package.json I get "require is not defined in ES module scope, you can use import instead". I don't really care about commonjs vs ecmascript module, but being forced to switch globally for one small dependency doesn't feel right. Using |
See README.md Requirements The esm lib is lacking updates and doesn't currently support optional chaining (elvis), so I've switched to esm-wallaby which is a fork of esm that does support optional chaining. |
I did read the README, I just didn't understand "ECMAScript module (esm), not native esm/.mjs with package.json type: module, requires esm" I suppose in the first part esm refers to the module system and in the second part to the esm node module that helps loading this type of module. I was simply saying that something a little bit more explicit, probably with an actual code example, would probably help others. |
I don't recommend native esm (type: module, or .mjs extension) because it locks modules from manipulation. Instrumentation with newrelic agent and mocking don't work. Using esm or esm-wallaby supports all the ES6 features but doesn't lock the code. |
Thanks for the feedback. I need to update my libraries, so I will take your advice and try to make the docs more clear. |
Thanks for this really useful library! However to use it in most applications it needs to be exported as a CommonJS module. Most bundlers do not process the
node_modules
folder so you get errors like this:The text was updated successfully, but these errors were encountered: