question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

expect NPM package unusable in browser

See original GitHub issue

šŸ› Bug Report

The expect NPM package is not usable in browser, although it has a browser: build-es5/index.js field.

To Reproduce

Add this to a static page:

<script src="/node_modules/expect/build-es5/index.js"></script>

It almost works, with the sole exception that the very last line fails: module.exports = expect Because thereā€™s no global module object.

Expected behavior

Should not throw and expose a global expect object.

If you detect that thereā€™s no module but a window instead, doing window.expect = expect makes everything work perfectly.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
SimenBcommented, Oct 22, 2018

Iā€™ve got a branch with some of the work done, you can work off of that: https://github.com/SimenB/jest/tree/esm-export

I think itā€™s just a matter of fixing the tests, and you should be good to go šŸ™‚

3reactions
SimenBcommented, Oct 6, 2018

Ah, itā€™s https://github.com/rollup/rollup/issues/1646 combined with https://github.com/facebook/jest/blob/d59a4d33b6aff50df3f2a307d71797a5d0e5f298/packages/expect/src/index.js#L389

Since our next release is a major, we should probably go through and remove all module.exports usage in favor of export default. It will force people using require to do .default, but hopefully itā€™s not too big of a deal

Read more comments on GitHub >

github_iconTop Results From Across the Web

expect - npm
This package exports the `expect` function used in [Jest](https://jestjs.io/). ... Start using expect in your project by running `npm i expect`.
Read more >
npm not working - "read ECONNRESET" - Stack Overflow
I'd been trying to get past this off and on for months. I had been just disabling VPN, grabbing packages, then logging back...
Read more >
Top 10 Most Common Node.js Developer Mistakes - Toptal
JavaScript in Node.js (just like in the browser) provides a single ... by a package to do something asynchronously is designed to expect...
Read more >
browser-error-classes - npm Package Health Analysis - Snyk
The npm package browser-error-classes was scanned for known vulnerabilities and missing license, and no issues were found. Thus the package was deemed as...
Read more >
Installing with NPM - Kendo UI for jQuery
The scripts in the NPM package are not usable in the browser. To work around this issue, use a bundler such as WebPack....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found