'How should the following configuration of exports in 'package.json' be imported and used correctly?

package.json

"exports": {
    "node": {
      "import": "./edition-es5-esm/index.js",
      "require": "./edition-es5/index.js"
    }
},

use

import versionCompare from 'version-compare';
// Error

Module not found: Error: Package path . is not exported from package



Solution 1:[1]

Are you using workspaces? Are you using npm? yarn? pnpm? Are you using typescript? Pure ESM or mixed in CJS? Do you have any custom configurations set about import path resolution?

Lots of questions here, but overall, it seems like you may be trying to emulate behavior of a monorepo (management tool) like lerna or similar

I think this page in node's docs may also help with understanding what this field does, and how to make it work like I presume you want! :)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mytch