[SOLVED] NFT Whale Watcher Project - Cannot find module 'moralis/node'

Hi There,

I have been tying to run “node stats.js” but keep getting an error message,

I have already successfully executed the followings in the “stats” directory, “npm i moralis” and “npm i fs”.

All steps before this also did not gave me any problems.

but some how no matter what I have tried I still get the “throw err” (see below) when I try to run “node stats.js” after saving “stats.js”.

node:internal/modules/cjs/loader:936
throw err;
^

Error: Cannot find module ‘moralis/node’
Require stack:

  • C:\Users\cryra\Whalewatcher-Web3\stats\stats.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object. (C:\Users\cryra\Whalewatcher-Web3\stats\stats.js:1:17)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions…js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
    code: ‘MODULE_NOT_FOUND’,
    requireStack: [ ‘C:\Users\cryra\Whalewatcher-Web3\stats\stats.js’ ]
    }

“stats” directory Package.json below
{

“name”: “stats”,

“version”: “1.0.0”,

“description”: “”,

“main”: “index.js”,

“scripts”: {

"test": "echo \"Error: no test specified\" && exit 1"

},

“author”: “”,

“license”: “ISC”,

“dependencies”: {

"fs": "^0.0.1-security",

"moralis": "^2.0.1"

}

}

Your help very much appreciated. Thank You.

Windows 11
npm 8.3.0

Where from do you have this dependency? This is the dependency that you want to use? Moralis v2?

1 Like

This dependency auto populated Package.json after I ran “npm i moralis” are you saying the version num is wrong?

There’s an update regarding Moralis 2.0 Explained here
So you need to make a little fix to your app. You need to remove moralis and install moralis-v1 and also change the require statement

// To remove morali
npm remove moralis

// To install moralis-v1
npm install moralis-v1

Change the require statement too

// From
const Moralis = require("moralis/node");

// To
const Moralis = require("moralis-v1/node");
3 Likes

Nice, its working now.

1 Like