Error in production in vue, TypeError: Right-hand side of ‘instanceof’ is not callable

Hey Guys,

I’ve recently tried to publish a new project and the production build is throwing the error: Uncaught (in promise) TypeError: Right-hand side of ‘instanceof’ is not callable

It doesn’t happen on dev build but if remove Moralis the error disappears,

this is using Vite and Vue.js.

Has anyone else experienced this?

Can you post a code snippet of the function/line that error is coming from?

I also experience this error with basic vite and react-ts. I copied the code from

https://docs.moralis.io/moralis-dapp/connect-the-sdk/connect-with-react

No issues with dev but when building and deploying, it spits out the same error as above.

I don’t have any other code than the default vite react-ts template and the moralis connect-with-react.

Oh I needed to add package @walletconnect/web3-provider to make it work on dev. Not sure if that’s related.

Where do you deploy it? Does the same issue happen on another platform e.g. Netlify?

Actually no need to deploy. Just run locally the build script then preview to see the error.

@alex I added my codes here:

Try preview your build locally with serve using serve -s build to preview that

Yes correct. No need to deploy anywhere. Just preview the build locally and the error will appear.

I forgot where I read this but its something todo with the way vite does the rollups on production. If you change your import statements to: import Moralis from ‘moralis/dist/moralis.js’; it will work

1 Like

Is that an issue with all regular imports without direct paths?

I got this error too. It runs well in localhost, but the error shows after building. My website is deployed on github page https://wesleytw.github.io/lava-test/
source code: wesleytw/lava-test at gh-pages (github.com)

Also having this issue, has anyone been able to resolve it? I’m deploying from a vite app

2 Likes

I’m also having the same issue guys. Any workaround?

Have you seen this topic?

1 Like

Yes, we did already and the error persists.

Ok. What solutions have you tried from that topic?

I will spend some time today with a Vite/React/Moralis project to have a look.

1 Like

We’ve tried all solutions so far such as replacing react-moralis for moralis sdk, configuring commonjs vite plugin and more. Right now we are working on the moralis sdk package itself to see if we can do something. I will keep you guys updated.

I have not been able to find a solution. For me the error only happens when using MoralisProvider; seems to be related to bundling. Unfortunately not using MoralisProvider is not really a solution as that negates the purpose of react-moralis entirely.

1 Like

Hi everyone, I actually found a solution for my problem, and maybe you guys are coming across the same problem.

I got rid of this error and I was able to build successfully my project:

Parsing error: Invalid right-hand side in an assignment expression

The problem I found is in 3 files (The image attached has the fixes already):

Basically, you will have to remove the function interopRequireDefault() from imports in three files:
node_modules/moralis/lib/browser/encode.js
node_modules/moralis/lib/browser/decode.js

  • ParseFile
  • ParseGeoPoint
  • ParsePolygon
  • ParseObject
  • ParseACL
  • ParseOp
  • ParseRelation

and in the file node_modules/moralis/lib/browser/Cloud.js

  • ./decode
  • _encode
  • ParseError
  • ParseQuery

Unfortunately, this is inside the moralis package so maybe someone will see this post and will improve it, the Parse files are actually coming with a default object duplicated because of this function, and maybe the way vite is building the project. (I’m not sure)

function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : {
    "default": obj
  };
}

module.exports = _interopRequireDefault, module.exports.__esModule = true, module.exports["default"] = module.exports;

as the example below:

{
   default: {
    _esModule: true,
    default: {}
 }
}

Hopefully, it can be helpful for anyone around here who was struggling to build the react project with Vite because of Moralis SDK.

2 Likes

Wonderful, can you please post this on the Moralis GitHub SDK page?

1 Like