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