NPM Package path is not exported from package – Javascript

by
Ali Hasan
es6-modules node-modules node.js package.json

Quick Fix: Modify your files property in package.json to "files": ["dist"]. Update your exports to be more specific, like "exports": { "import": { "./Application.js": "./dist/esm/Application.js" }, "require": { "./Application.js": "./dist/cjs/Application.js" } }. Then, simplify your import statements to import {app} from '@mypackage/Application.js'. Consider using @knighted/duel to simplify your build process.

The Problem:

A developer is trying to import an object from their newly built NPM package, but encountering an error message stating "Module not found: Error: Package path ./src/Application is not exported from package". Despite successful installation of the package, the IDE and NPM fail to recognize any exported files or definitions. The developer has tried various combinations of import statements to no avail.

Q&A

Why is nothing from my project exported?

The exported path was not defined correctly in package.json.

What should be the value of files in package.json?

The value of files should be "dist" in package.json.

Video Explanation:

The following video, titled "Package JSON Demystified - The 'Exports' Keyword - YouTube", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

In this Javascript tutorial on NPM Package.JSON we look at the 'EXPORTS' keyword and how it helps us expose and also encapsulate the ...