rmrk-tools icon indicating copy to clipboard operation
rmrk-tools copied to clipboard

publish dual packages (ESM + CommonJS)

Open gabrieljaegerde opened this issue 4 years ago • 3 comments

is it possible to to publish dual packages (ESM + CommonJS), using conditional exports?

gabrieljaegerde avatar Sep 06 '21 13:09 gabrieljaegerde

Is it possible to use rmrk-tools with node? When I try to use it with imports/exports module I get the following error:

$ node script.js
file:///Users/bruno/src/examples/node-dot/getRemarks.js:1
import { fetchRemarks, getRemarksFromBlocks, getLatestFinalizedBlock, Consolidator } from 'rmrk-tools';
                                                                      ^^^^^^^^^^^^
SyntaxError: Named export 'Consolidator' not found. The requested module 'rmrk-tools' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'rmrk-tools';
const { fetchRemarks, getRemarksFromBlocks, getLatestFinalizedBlock, Consolidator } = pkg;

brunopgalvao avatar Mar 08 '22 14:03 brunopgalvao

yes. rmrk has yet to solve this issue. I just end up adding "type": "module" to the rmrk-tools package.json . It is a bit tedious to do it each time I update the dependency but that is my fix for now.

gabrieljaegerde avatar Mar 11 '22 10:03 gabrieljaegerde

It would be nice if "type": "module" could be added to the package json.

yornaath avatar Oct 25 '22 10:10 yornaath