js-waku
js-waku copied to clipboard
Invalid exports field in the package.json
This is a bug report.
Problem
We are using jest for running tests on the Status Web. The ecosystem is still in the early adoption of exports
field, but Jest recently added supported to the jest-resolve
. The tests were failing on the error message Cannot find module 'js-waku' from <FILE_NAME>
. It took me a while, but I found the culprit.
#621 introduced invalid exports
field definition to the package.json
. The main issue is that import condition is not pointing to a valid file that can be loaded via import
or import()
(because it is a CommonJS build).
Proposed Solutions
After reading Node.js Packages documentation and Webpack Package Exports article, I believe the correct configuration is the following:
{
"exports": {
"node": {
"import": "./build/esm/index.js",
"require": "./build/main/index.js",
}
"default": "./build/esm/index.js"
},
}
-
import
condition pointing to ESM build -
require
condition pointing to CommonJS build -
default
condition is a generic fallback that always matches and should be last
Unless you have environment-specific code, it is not necessary to use the node
condition. However, it seems to be a good practice to be explicit about it.
Should be fixed once #802 is done
Fixed in 0.25.0