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

browser field of package.json not used? #557

Open
D4nte opened this issue May 5, 2022 · 0 comments
Open

browser field of package.json not used? #557

D4nte opened this issue May 5, 2022 · 0 comments

Comments

@D4nte
Copy link

D4nte commented May 5, 2022

I am trying to clean up the use of node vs browser API in my repo by using the browser field in my package.json:

{
  "browser": {
    "./lib/crypto_subtle.js": "./lib/crypto_subtle_browser.js"
  }
}

I understand that karma-typescript uses browser-resolve to also use the field, however, it does not seem to work:

Chrome Headless 100.0.4889.0 (Linux x86_64) ERROR
  Uncaught Error: node crypto api unavailable
  at src/lib/crypto_subtle.ts:9:1 <- src/lib/crypto_subtle.js:14:5
  
  Error: node crypto api unavailable
      at Object.global.wrappers./home/fryorcraken/src/status-im/js-waku/src/lib/crypto_subtle.ts.crypto (src/lib/crypto_subtle.ts:9:7 <- src/lib/crypto_subtle.js:14:11)
      at require (node_modules/karma-typescript/dist/client/commonjs.js:17:25)
      at node_modules/karma-typescript/dist/client/commonjs.js:18:24
      at Object.global.wrappers./home/fryorcraken/src/status-im/js-waku/src/lib/crypto.ts../crypto_subtle (src/lib/crypto.ts:3:18 <- src/lib/crypto.js:6:25)
      at require (node_modules/karma-typescript/dist/client/commonjs.js:17:25)
      at node_modules/karma-typescript/dist/client/commonjs.js:18:24
      at Object.global.wrappers./home/fryorcraken/src/status-im/js-waku/src/lib/enr/v4.ts.js-sha3 (src/lib/enr/v4.ts:9:22 <- src/lib/enr/v4.js:27:18)
      at require (node_modules/karma-typescript/dist/client/commonjs.js:17:25)
      at node_modules/karma-typescript/dist/client/commonjs.js:18:24
      at Object.global.wrappers./home/fryorcraken/src/status-im/js-waku/src/lib/enr/index.ts../v4 (src/lib/enr/index.ts:3:1 <- src/lib/enr/index.js:28:31)

The crypto_subtle.js file is used instead of crypto_subtle_browser.js.

Do I need to enable browser-resolve?

To Reproduce

git clone https://github.com/status-im/js-waku.git
git checkout origin/browser-resolve
npm i
npm run test:karma
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

No branches or pull requests

1 participant