Open
Description
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
Metadata
Metadata
Assignees
Labels
No labels