Create a script to polyfill requiring ES package "exports" for nodejs 12 below.
$ npm install -D polyfill-exports
# or
$ yarn add --dev polyfill-exports
Build the polyfill script:
$ npx polyfill-exports
# or
$ yarn run polyfill-exports
then add the script into package.json "files" and "postinstall" hook.
// your package.json
{
...,
"exports": {
"foo": "./lib/foo.js"
},
"script": {
"postinstall": "node ./polyfill-exports.js"
},
"files": [
...,
"polyfill-exports.js"
]
...
}
$ npx polyfill-exports --delete
# or
$ yarn run polyfill-exports --delete