js-waku icon indicating copy to clipboard operation
js-waku copied to clipboard

Invalid exports field in the package.json

Open prichodko opened this issue 2 years ago • 1 comments

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.

prichodko avatar May 31 '22 08:05 prichodko

Should be fixed once #802 is done

D4nte avatar Jun 22 '22 03:06 D4nte

Fixed in 0.25.0

fryorcraken avatar Sep 05 '22 10:09 fryorcraken