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

ESM support breaks custom validator initialization #1106

Closed
4 tasks done
pibi opened this issue Jul 19, 2022 · 1 comment
Closed
4 tasks done

ESM support breaks custom validator initialization #1106

pibi opened this issue Jul 19, 2022 · 1 comment

Comments

@pibi
Copy link

pibi commented Jul 19, 2022

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed
  • I'm reporting the issue to the correct repository

Current Behavior

When requiring the base module to setup a custom validator, node v16.14.2 throws an exception with moleculer 0.14.21:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './src/validators/base' is not defined by "exports" in /project/node_modules/moleculer/package.json

see below for a full log. Works correctly with moleculer 0.14.20

Expected Behavior

Should correctly require the module. For fully custom validator support we also need the following requires to work:

const BaseValidator = require("moleculer/src/validators/base");
const FallbackValidator = require("moleculer/src/validators/fastest");
const {ValidationError} = require("moleculer/src/errors");

All these do not work with 0.14.21

Steps to Reproduce

With moleculer v.014.21:

  1. open a node v16.x CLI
  2. require("moleculer/src/validators/base");
  3. see the exception error

Failure Logs

Welcome to Node.js v16.14.2.
Type ".help" for more information.
> const BaseValidator = require("moleculer/src/validators/base");
Uncaught:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './src/validators/base' is not defined by "exports" in /project/node_modules/moleculer/package.json
    at __node_internal_captureLargerStackTrace (node:internal/errors:464:5)
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:453:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:731:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
@pibi pibi changed the title ESM support break custom validator initialization ESM support breaks custom validator initialization Jul 19, 2022
@pibi
Copy link
Author

pibi commented Jul 19, 2022

Fixed at our side by importing right from moleculer:

const { Validators, Errors: { ValidationError } } = require("moleculer");

see: pibi/moleculer-json-schema-validator@d574f04

@pibi pibi closed this as completed Jul 19, 2022
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

1 participant