Skip to content

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in C:\user\Node-red\node_modules\@jsonquerylang\jsonquery\package.json #27

Closed

Description

@strbaknxp

Hello,
I'm trying to use @jsonquerylang/jsonquery version 5.0.4 in a Node-RED environment, which relies on CommonJS modules and synchronous require() calls in its settings.js configuration file.
Unfortunately, the current version of the package does not define an "exports" field in its package.json, and it appears to be bundled as a pure ESM module. This causes the following error when attempting to use it via require():
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in node_modules/@jsonquerylang/jsonquery/package.json

This makes it impossible to use the package in environments like Node-RED that do not support import() or asynchronous module loading in configuration files.

What we need:
A defined "exports" field in package.json that allows access to the main entry point (e.g. jsonquery, compile, etc.) via CommonJS require().
Alternatively, a dual-module build (ESM + CommonJS) or a separate CommonJS-compatible wrapper.

Why this matters:
Node-RED is widely used in industrial and automation environments, and many users rely on synchronous module loading via require() in settings.js. Without CommonJS compatibility, it's currently impossible to use jsonquery in global context or in standard function nodes without resorting to async hacks or custom node development.
Would it be possible to add CommonJS support or at least expose the main entry point via "exports"?
Thank you for your great work on this library — it’s extremely useful and powerful, and we’d love to be able to use it in more environments.

Activity

  1. josdejong commented on Nov 11, 2025

    @josdejong
    Collaborator

    The library is indeed just ESM.

    What version of Node.js are you using? Since Node.js v22 you can load ESM modules via require too (see article).

  2. strbaknxp commented on Nov 11, 2025

    @strbaknxp
    Author

    Oh oki,
    thanks a lot, I am using old v20. I will try to update. Thank you :)

  3. strbaknxp commented on Nov 13, 2025

    @strbaknxp
    Author

    Hello,

    I was trying to install new version of node. Now I am using latest LTS: 24.11.1 but basically I have the same problem.
    When I do const JSONQuery = require('@jsonquerylang/jsonquery');
    I get "[object Promise]" instead of a function. This breaks existing code because the module is ESM-only and require() returns a Promise.

    If I try to use import I get: Error: Module not allowed
    seems like Node-RED sandbox does not allow dynamic imports.

  4. josdejong commented on Nov 13, 2025

    @josdejong
    Collaborator

    I just tested in a CommonJS file and you can indeed load the ESM library in Nodejs 22 and newer via:

    const { jsonquery, compile, parse, stringify } = require('@jsonquerylang/jsonquery')

    I'm not familiar with Node-RED so I'm not sure what they do and don't support. Since all of the JavaScript ecosystem is moving towards ESM it sounds important to me that Node-RED supports ESM too. Maybe you should ask about this at Node-RED itself?

  5. added
    question
    on Nov 13, 2025
  6. josdejong commented on Nov 13, 2025

    @josdejong
    Collaborator

    The following issue suggests that ESM can be loaded (after the issue was fixed): node-red/node-red#3627 . Does that help?

  7. strbaknxp commented on Nov 14, 2025

    @strbaknxp
    Author

    Hello, Thank you for your support.
    Actually it does not help because is pretty old - this we was using till now but for new versions of NR it does not work anymore.
    But I also left there a question so I believe they will able to provide some solution.

    Thanks a lot :)

  8. josdejong commented on Nov 14, 2025

    @josdejong
    Collaborator

    👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions