skip to Main Content

I have a Nuxt.js 3 (rc4) application running well on the dev server, but the production build crashes on start. I’m using Mongoose to connect to a Mongo DB and the issue seems to be there, particularly with the whatwg-url package used by Mongoose or one of its dependencies.

After running in debug mode I can see that whatwg_url_1.URL is undefined and it should be a class.

I’m using the latest versions of Nuxt (3.0.0-rc.4) and Mongoose (6.4.0).

Here’s the output:

/var/app/.output/server/node_modules/mongodb-connection-string-url/lib/index.js:74
class URLWithoutHost extends whatwg_url_1.URL {
                                          ^

TypeError: Class extends value undefined is not a constructor or null
    at Object.<anonymous> (/var/app/.output/server/node_modules/mongodb-connection-string-url/lib/index.js:74:43)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/var/app/.output/server/node_modules/mongodb/lib/connection_string.js:6:41)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)

EDIT:
There seems to be an incompatibility between Mongoose/MongoDB and another library, google-auth-library. Removing one or the other makes it run.
Related issue report

On build it warns the following:

 WARN  Multiple major versions of package webidl-conversions are being externalized. Picking latest version.                                                         16:06:10  
  - .../node_modules/gaxios/node_modules/[email protected]
  - .../node_modules/[email protected]

2

Answers


  1. I’ve encountered the same issue and also haven’t found a solution yet, as you mentioned, it is a conflict with libraries that use an npm package called whatwg-url like google-auth-library or in my case @nuxtjs/supabase

    This only happens when in production mode, but when using nuxi dev everything runs smoothly. I’m wondering if there are some build configurations that can be added to solve this issue

    The dependency graph looks like this:

    dependencies:
    mongoose 6.5.3
    └─┬ mongodb 4.8.1
      └─┬ mongodb-connection-string-url 2.5.3
        └── whatwg-url 11.0.0
    
    devDependencies:
    @nuxtjs/supabase 0.1.23
    └─┬ @supabase/supabase-js 1.35.6
      ├─┬ @supabase/functions-js 1.3.4
      │ └─┬ cross-fetch 3.1.5
      │   └─┬ node-fetch 2.6.7
      │     └── whatwg-url 5.0.0
      ├─┬ @supabase/gotrue-js 1.22.22
      │ └─┬ cross-fetch 3.1.5
      │   └─┬ node-fetch 2.6.7
      │     └── whatwg-url 5.0.0
      ├─┬ @supabase/postgrest-js 0.37.4
      │ └─┬ cross-fetch 3.1.5
      │   └─┬ node-fetch 2.6.7
      │     └── whatwg-url 5.0.0
      └─┬ @supabase/storage-js 1.7.3
        └─┬ cross-fetch 3.1.5
          └─┬ node-fetch 2.6.7
            └── whatwg-url 5.0.0
    nuxt 3.0.0-rc.8
    └─┬ nitropack 0.4.24
      └─┬ @vercel/nft 0.21.0
        └─┬ @mapbox/node-pre-gyp 1.0.9
          └─┬ node-fetch 2.6.7
            └── whatwg-url 5.0.0
    
    Login or Signup to reply.
  2. I’ve encountered the same issue with Nuxt3, @Khaled’s post is very helpful. In my case this is caused by whatwg-url conflict in node-fetch and mongodb, very similar if not identical to what @Khaled’s has encountered. Simply forcing the dependency version seems to work for me.

    So in your package.json, add:

    "overrides":{ "whatwg-url": "11.0.0"   }
    

    Then to be safe, remove node_modules directory and yarn.lock or package.lock.json, reinstall packages, run something like yarn why whatwg-url and see if it’s using the updated version.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search