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
Issues building with Vite/Rollup: "TypeError: Cannot read property 'Decimal128' of null" #12335
Comments
Could you please provide a code sample or perhaps the code leading to that point where the error is thrown? |
Somewhere someone has already fixed it. I think the problem was in sveltekit or the adapter. |
Reproduction: https://stackblitz.com/edit/sveltejs-kit-template-default-jysxco?file=src/hooks.server.js ...
var mongoose$1 = {
exports: {}
};
var lib$5 = {
exports: {}
};
var driver$1 = {};
/*!
* ignore
*/
let driver = null;
driver$1.get = function () {
return driver;
};
driver$1.set = function (v) {
driver = v;
};
...
/**
* Decimal128 type constructor
*
* #### Example:
*
* const id = new mongoose.Types.Decimal128('3.1415');
*
* @constructor Decimal128
*/
var decimal128$3 = driver$1.get().Decimal128; //here
var symbols$3 = {};
symbols$3.arrayAtomicsBackupSymbol = Symbol('mongoose#Array#atomicsBackup');
... |
@AlexRMU I don't see any errors? Maybe I just don't understand how to use StackBlitz |
The error appears after the build is runned.
|
This looks like a bug with how Vite handles bundling. Like you mentioned, the general structure of the file Vite outputs looks like this:
The problem is that the The following doesn't work:
Nor does moving the |
Here is a Reproduction of this issue with a blank SolidStart app: |
There is a lot of circular dependencies going on in mongoose, but in my case this error could be avoided by configuring the @rollup/plugin-commonjs with the configuration: { strictRequires: true } (see more here) |
I took a look and this is still an issue. New error message is the following:
Here's the logic that sets
That logic is after the logic that initializes the Mongoose singleton:
Not sure why this is happening, I don't see any circular imports related to driver imports in particular. But we'll take a look and see if we can resolve some of the circular imports. |
Maybe it's a rollup bug |
Yeah all of those are valid explanations, but unfortunately not necessarily viable courses of action at this time. Apparently you can fix this with strictRequires option in Vite/rollup, but I'd love to see if there's a way we can fix this without requiring that option |
I've encountered the same problem, setting the options of @rollup/plugin-commonjs to { strictRequires: true } does works. |
Prerequisites
Mongoose version
6.5.3
Node.js version
16.15.0
MongoDB server version
4.4
Description
I'm trying to create a bundle for the prod.
I use esbuild, vite, rollup, sveltekit.
An error appears during building:
Possibly related to #7866
Steps to Reproduce
It is difficult
Expected Behavior
No response
The text was updated successfully, but these errors were encountered: