Cannot find package '@moralis/sdk'

Hey guys! I’m requesting Moralis SDK from my module JS App. Installed (npm install moralis) sdk, then I got error Error [ERR_MODULE_NOT_FOUND]: Cannot find package ‘@moralis/sdk’ imported from …/app.js on this code

import { Moralis } from '@moralis/sdk';

Changed to

import { Moralis } from 'moralis';
got

CommonJS modules can always be imported via the default export, for example using:
import pkg from 'moralis';
const { Moralis } = pkg;

After changing to above code got

await Moralis.start({
              ^

TypeError: Cannot read properties of undefined (reading 'start')

Any suggestions?

what type of project it is?

new JS module app. npm init, then “type”: “module” in package.json

this is what it was working for moralis v1 sdk in node js for me:

const Moralis = require('moralis/node');

ReferenceError: require is not defined in ES module scope, you can use import instead

Changed to

import { start as _start, EvmApi } from ‘moralis/node’;

Error [ERR_MODULE_NOT_FOUND]: Cannot find package ‘moralis’ imported from /Users/leo/dev/web30/app.js

both packages moralis and moralis-v1 are installed

this is a simple node js application?

ES6 module app. It works pretty well if I use commonJs (const … require, as in your example). But my requirement is ES6…

I don’t know what should be the solution in this case

both packages moralis and moralis-v1 are installed

Do you want to use moralis-v1 or moralis (2.0)?

I’d like to use moralis (2.0) NFT API… (sorry, updated my post)

I found out about this syntax today for a simple node js project, probably doesn’t help you:

Moralis = require("moralis").default

@tijuana, found out a possible solution:

import Moralis from "moralis"
const Moralis2 = Moralis.default

and then use Moralis2 instead of Moralis

3 Likes