moleculer
moleculer copied to clipboard
Moleculer ESM Runner export
Prerequisites
Please answer the following questions for yourself before submitting an issue.
- [x] I am running the latest version
- [x] I checked the documentation and found no answer
- [x] I checked to make sure that this issue has not already been filed
- [x] I'm reporting the issue to the correct repository
Current Behavior
Importing MoleculerRunner while having {"type": "module"} in package.json imports cjs version of MoleculerRunner.
Expected Behavior
Esm version on MoleculerRunner should be exported from "index.mjs"
Failure Information
Cjs version of moleculer runner is not compatible with esm project.
Create ESM project, create index.js file:
import { Runner } from 'moleculer';
const runner = new Runner();
runner.start(process.argv);
Run it.
Solution
Replacing index.mjs in moleculer repo with this fixes an issue
import mod from "./index.js";
import MoleculerRunner from './src/runner-esm.mjs';
export default mod;
export const CIRCUIT_CLOSE = mod.CIRCUIT_CLOSE;
export const CIRCUIT_HALF_OPEN = mod.CIRCUIT_HALF_OPEN;
export const CIRCUIT_HALF_OPEN_WAIT = mod.CIRCUIT_HALF_OPEN_WAIT;
export const CIRCUIT_OPEN = mod.CIRCUIT_OPEN;
export const Cachers = mod.Cachers;
export const Context = mod.Context;
export const Discoverers = mod.Discoverers;
export const Errors = mod.Errors;
export const INTERNAL_MIDDLEWARES = mod.INTERNAL_MIDDLEWARES;
export const Loggers = mod.Loggers;
export const METRIC = mod.METRIC;
export const MOLECULER_VERSION = mod.MOLECULER_VERSION;
export const MetricReporters = mod.MetricReporters;
export const MetricTypes = mod.MetricTypes;
export const Middlewares = mod.Middlewares;
export const PROTOCOL_VERSION = mod.PROTOCOL_VERSION;
export const Registry = mod.Registry;
export const Runner = MoleculerRunner;
export const Serializers = mod.Serializers;
export const Service = mod.Service;
export const ServiceBroker = mod.ServiceBroker;
export const Strategies = mod.Strategies;
export const TracerExporters = mod.TracerExporters;
export const Transit = mod.Transit;
export const Transporters = mod.Transporters;
export const Utils = mod.Utils;
export const Validator = mod.Validator;
export const Validators = mod.Validators;
Good catch. The problem is that, the mjs file is generated with gen-esm-wrapper