auth0.js: Upgrading to 9.7.2 causes test breakages

I upgraded from auth0-js 9.5.1 to ^9.7.2 and am now seeing the following error when running my jest tests:

/Users/[my-user]/[my-repo]/node_modules/auth0-js/src/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import Authentication from './authentication'

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 21 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks! That’s very helpful. I’ll dig through this today and I hope to have a patch by tomorrow.

9.7.0 should’ve been a major version bump, as any application participating in SSR is now broken. Alternatively, you should retain backwards compatibility by shipping both CommonJs and ESM versions of Auth0.

I just got bit by this in a Next.js application.

Great to hear, @lucascrespo! Looking forward to a fix. 😄

Apps will look at the main field when running via Node (SSR, or tests – like this issue) and the browser or module field when being consumed by webpack (normal bundle application).

General rule of thumb is as follows:

  • esnext: uncompiled sources, what main is currently set to
  • browser: compiled down to minimum supported browser version (and no ES Modules)
  • module: compiled down to minimum supported browser version, except that ES Modules remain in place
  • main: compiled down to minimum supported Node version

Most people opt for module and main, there’s not much value in shipping browser nor esnext.

Here’s a really simple repro case:

$ npx create-next-app example
$ cd example/
$ yarn add auth0-js
$ echo "import Auth0 from 'auth0-js'

export default () => <div />
" > pages/index.js
$ yarn dev
$
$ # new terminal
$
$ curl -s http://localhost:3000 | head -n5 | tail -n4
(function (exports, require, module, __filename, __dirname) { import Authentication from &#x27;./authentication&#x27;;                                                              ^^^^^^
SyntaxError: Unexpected token import
$ yarn add auth0-js@9.6.x
$ curl -s http://localhost:3000 | head -n1
<!DOCTYPE html><html><head><meta charSet="utf-8" class="next-head"/><link rel="preload" href="/_next/-/page/index.js" as="script"/><link rel="preload" href="/_next/-/page/_app.js" as="script"/><link rel="preloa
d" href="/_next/-/page/_error.js" as="script"/><link rel="preload" href="/_next/static/commons/manifest.js" as="script"/><link rel="preload" href="/_next/static/commons/main.js" as="script"/></head><body><div i
d="__next"><div></div></div><div id="__next-error"></div><script>