As you’re using ECMAScript modules, please refer to node.js docs on package entry points:
In a package’s package.json file, two fields can define entry points for a package: “main” and “exports”. The “main” field is supported in all versions of Node.js, but its capabilities are limited: it only defines the main entry point of the package.
The “exports” field provides an alternative to “main” where the package main entry point can be defined while also encapsulating the package, preventing any other entry points besides those defined in “exports”. This encapsulation allows module authors to define a public interface for their package.
So, in your package.json, you could define exports
like this:
"main": "dist/index.js",
"exports": {
".": "./dist/index.js",
"./nodejs": "./dist/nodejs",
"./web": "./dist/web",
}