Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid exports field in the package.json #770

Closed
prichodko opened this issue May 31, 2022 · 2 comments
Closed

Invalid exports field in the package.json #770

prichodko opened this issue May 31, 2022 · 2 comments

Comments

@prichodko
Copy link

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.

@D4nte
Copy link
Contributor

D4nte commented Jun 22, 2022

Should be fixed once #802 is done

dohaki added a commit to bosonprotocol/chat-sdk that referenced this issue Aug 2, 2022
When running the test with `jest`, it errored with
```
Cannot find module 'js-waku' from 'node_modules/@xmtp/xmtp-js/dist/cjs/src/utils.js'
```

The problem seems to be this issue
waku-org/js-waku#770.

Until this is resolved, we use a local patch as this only occurs when running tests.
dohaki added a commit to bosonprotocol/chat-sdk that referenced this issue Aug 2, 2022
When running the test with `jest`, it errored with
```
Cannot find module 'js-waku' from 'node_modules/@xmtp/xmtp-js/dist/cjs/src/utils.js'
```

The problem seems to be this issue
waku-org/js-waku#770.

Until this is resolved, we use a local patch as this only occurs when running tests.
dennisfurrer added a commit to bosonprotocol/chat-sdk that referenced this issue Aug 3, 2022
* Revert "feat: remove all tests related files (#2)"

This reverts commit 7cb60d8.

* build: add patch for js-waku not found (#7)

When running the test with `jest`, it errored with
```
Cannot find module 'js-waku' from 'node_modules/@xmtp/xmtp-js/dist/cjs/src/utils.js'
```

The problem seems to be this issue
waku-org/js-waku#770.

Until this is resolved, we use a local patch as this only occurs when running tests.

* Add unit and integration tests

* Implement review remarks

Co-authored-by: Dong-Ha Kim <[email protected]>
Co-authored-by: Dennis Furrer <[email protected]>
@fryorcraken
Copy link
Collaborator

Fixed in 0.25.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants