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

[v5] Need exports on Package.json for ESM support #61

Open
axmad386 opened this issue Jul 2, 2021 · 2 comments
Open

[v5] Need exports on Package.json for ESM support #61

axmad386 opened this issue Jul 2, 2021 · 2 comments

Comments

@axmad386
Copy link

axmad386 commented Jul 2, 2021

This is issue for version 5 (dev).
I currently use node-input-validator version next (v5). I love this next version, cannot wait for the stable release 😃 .
And the problem begin when I use it on esmodule.
This is the error throw when I import it from esmodule

import { extend, Messages, Validator } from 'node-input-validator';
         ^^^^^^
SyntaxError: The requested module 'node-input-validator' is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export.
For example:
import pkg from 'node-input-validator';
const { extend, Messages, Validator } = pkg;

Currently when I import node-input-validator, it still import the cjs version.

The fix is just add additional config "exports" in package.json
example

"main": "index",  
"module": "index.mjs",
"exports": {
    ".": {
        "import": "./esm/index.js",
        "require": "./cjs/index.js"
    }
},

Also you must add additional package.json on each folder with this bash script

#!/bin/sh
cat >cjs/package.json <<!EOF
{
    "type": "commonjs"
}
!EOF

cat >esm/package.json <<!EOF
{
    "type": "module"
}
!EOF

You can read more here how to make hybrid nodejs package

For now, I am still use the cjs version and import it with @rollup/plugin-commonjs

@bitnbytesio
Copy link
Owner

Thanks for the information, will add soon. FYI: Currently, I 'm working on nested inputs logic, will rollout new release soon. Stable version soon after this.

@axmad386
Copy link
Author

axmad386 commented Jul 16, 2021

Hi, glad to hear that. Thanks for your hardworking. Cannot wait for the stable version 👍
btw, thanks for merging my PR

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