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
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
likegoogle-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 issueThe dependency graph looks like this:
I’ve encountered the same issue with Nuxt3, @Khaled’s post is very helpful. In my case this is caused by
whatwg-url
conflict innode-fetch
andmongodb
, 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:Then to be safe, remove
node_modules
directory andyarn.lock
orpackage.lock.json
, reinstall packages, run something likeyarn why whatwg-url
and see if it’s using the updated version.