React-moralis + moralis npm package not working anymore

Moralis version 0.0.39
React-Moralis version 0.2.1

Apps started crashing after updating to latest version with error:

ReferenceError: window is not defined
  at Object.<anonymous> (..\node_modules\moralis\lib\browser\UnitConvert.js:11:12)
  at Module._compile (internal/modules/cjs/loader.js:1085:14)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
  at Module.load (internal/modules/cjs/loader.js:950:32)
  at Function.Module._load (internal/modules/cjs/loader.js:790:14)
  at Module.require (internal/modules/cjs/loader.js:974:19)
  at require (internal/modules/cjs/helpers.js:92:18)
  at Object.<anonymous> (..\node_modules\moralis\lib\browser\Parse.js:340:17)
  at Module._compile (internal/modules/cjs/loader.js:1085:14)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
  at Module.load (internal/modules/cjs/loader.js:950:32)
  at Function.Module._load (internal/modules/cjs/loader.js:790:14)
  at Module.require (internal/modules/cjs/loader.js:974:19)
  at require (internal/modules/cjs/helpers.js:92:18)
  at Object.<anonymous> (..\node_modules\moralis\index.js:1:18)
  at Module._compile (internal/modules/cjs/loader.js:1085:14)

Was working perfectly with the previous versions. Using with React + nextjs.

Hey @minter

Could you share your github repo so that we can reproduce the error?

Sorry, I canโ€™t share the repo atm. Can you confirm that the react + react-moralis is working on your end with the latest versions?

Also when rolled back all the way to

"moralis": "0.0.30",
"react-moralis": "^0.2.0",

=> the app works. Was there any braking changes between those versions that I am just missing?

Here is a working boilerplate on the latest versions. Only react+react-moralis

Was there any braking changes between those versions that I am just missing?

I need time to find out about this, I will definitely let you know. :raised_hands:

Gotcha, thanks. I think it has to be a change that is not working with nextjs anymore.

1 Like

Commented everything Moralis related from the nextjs app its enough to add:

import { MoralisProvider } from "react-moralis";

to make it crash with that error

1 Like

Update, the issue is definitely introduced in moralis : 0.0.38. With the moralis 0.0.37 the react-moralis 0.2.1 works normally.

Also boiler plate example : https://github.com/jeere/moralis-issue

Hey @minter

Thank you for info. Iโ€™ve already looked into this bug. The fix will be in the next version. Iโ€™ll let you know :raised_hands:

1 Like

Hey @minter

The bug has been fixed.
Update to 0.0.41

Happy BUIDLing :man_mechanic:

Iโ€™ve been stuck on this for a few days, Iโ€™m using 0.0.41 and Next.js having all kinds of problems. When I yarn add moralis I get a lot of old depreciated warnings and I canโ€™t deploy to Netlify.
adding "resolutions": { "moralis/uuid": "^7.0.0", "moralis/web3": "^1.5.2" }, to my package.json forcing the submodules to use laterversion lets me deploy my site but now I get a bunch of console warnings and cant actually authenticate with metamask/moralis.
I can try to reproduce shortly

Hi @tanabota

Before updating the SDK version to 0.0.41 we have tasted it. And it works correctly, my package.json:

{
  "name": "next-js-template",
  "version": "1.0.0",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start",
    "type-check": "tsc"
  },
  "dependencies": {
    "@walletconnect/web3-provider": "^1.6.5",
    "isomorphic-unfetch": "3.0.0",
    "next": "latest",
    "react": "^16.10.1",
    "react-dom": "^16.10.1",
    "react-moralis": "0.2.1"
  },
  "devDependencies": {
    "@types/node": "^12.7.8",
    "@types/react": "^16.9.3",
    "@types/react-dom": "^16.9.1",
    "typescript": "3.6.3"
  },
  "license": "ISC",
  "keywords": [],
  "description": ""
}

If you share your repository on github or at least show us an error message then we will be able to solve your problem :man_mechanic:

Maybe you should uninstall the previous build .next and compile it all over again?

Hi all.

My Next.js/Moralis Repo

I am also using next.js and moralis and having the same issue. I would be happy with older versions of moralis, but when I want implement great features such as the 1inch plugin, I am stuck.

My error:

ReferenceError: window is not defined
    at Object.51.@babel/runtime-corejs3/helpers/classCallCheck (H:\Programming\sharpart\sharpart-frontend\node_modules\moralis\dist\moralis.js:24264:65)
    at o (H:\Programming\sharpart\sharpart-frontend\node_modules\moralis\dist\moralis.js:7:632)
    at H:\Programming\sharpart\sharpart-frontend\node_modules\moralis\dist\moralis.js:7:683
    at Object.<anonymous> (H:\Programming\sharpart\sharpart-frontend\node_modules\moralis\dist\moralis.js:7620:17)
    at Object.<anonymous> (H:\Programming\sharpart\sharpart-frontend\node_modules\moralis\dist\moralis.js:7730:4)
    at Object.23../Analytics (H:\Programming\sharpart\sharpart-frontend\node_modules\moralis\dist\moralis.js:7730:17)
    at o (H:\Programming\sharpart\sharpart-frontend\node_modules\moralis\dist\moralis.js:7:632)
    at r (H:\Programming\sharpart\sharpart-frontend\node_modules\moralis\dist\moralis.js:7:798)
    at H:\Programming\sharpart\sharpart-frontend\node_modules\moralis\dist\moralis.js:7:827
    at H:\Programming\sharpart\sharpart-frontend\node_modules\moralis\dist\moralis.js:7:88
    at Object.<anonymous> (H:\Programming\sharpart\sharpart-frontend\node_modules\moralis\dist\moralis.js:7:323)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Module.require (internal/modules/cjs/loader.js:1026:19)

Edit: I am planning to put Moralis@latest on a separate node js backend as temporary fix.

1 Like

Hey @Archie.S

The fact is that Moralis Js SDK primarily developed an architecture for users who do not use the backend. After all, our main goal is to create a simple and reliable way to create applications without using a backend.

We are currently working on adapting it for apps with server-side too :man_factory_worker:

Since the Next.js package uses backend-side rendering you get this window is not defined error.

I will let you know when the plugin feature will be compatible with Next.js :raised_hands:

1 Like

Hey @Yomoo

Great response as always. Apologies for my absence in this thread and the forum in general. Keep being amazing.

Hey @Archie.S

Nice to have you back!

Have you tried this functionality with Next? It should work correctly now

Please let me know how it works for you

Hi @Yomoo

I currently have a new issue with Next js after the recent updates, which I shall write into a new post very soon.

Edit: I shall not be writing a new post, because I have just solved my issue. Although in short, I was calling Moralis.initialise, in a Redux thunk. So when Next JS runs _app.tsx on the server (with Redux wrapping the app), the console was giving me a window reference error pointing to Moralis. It passed my mind that I was initialising Moralis here in Redux but, Iโ€™m glad I have noticed now. I shall refactor my code to avoid this. This is definitely what was giving me the Reference error.

For now I shall keep this here, but if a new post is required, I can post it up. Thanks again for the cooperation @Yomoo