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

Hey guys !

I found Moralis’ API really cool so I’m trying to use it in a project of mine, but whenever I try to initialize Moralis with my app’s credentials while using an ES6 import (import Moralis from 'moralis/node';) to add Moralis’ JS SDK to my NestJS back-end app, I get this error :
TypeError: Cannot read properties of undefined (reading 'start').

Using the old way of importing node packages (const Moralis = require('moralis/node');) “fixes” it, but I can’t figure out why it the error I described above happens.

Does anybody know how to fix this issue I’m having ?

that error sounds like Moralis variable is undefined in the first case, assuming that somewhere you call Moralis.start.

You’re right, and that’s what I want to do, but for some reason the imported module seems to be undefined.

Here’s the file where I’m having the issue (main.ts) :

import { NestFactory } from '@nestjs/core';
import * as compression from 'compression';
import { AppModule } from './app.module';
import Moralis from 'moralis/node';

async function bootstrap() {
  try {
    const app = await NestFactory.create(AppModule);

    app.use(compression());
    app.enableCors();

    await Moralis.start({
      serverUrl: process.env.MORALIS_SERVER_URL,
      appId: process.env.MORALIS_APP_ID,
    });

    await app.listen(process.env.BACKEND_PORT);

    const NFTs = await Moralis.Web3API.token.getAllTokenIds({
      address: '0x9a534628b4062e123ce7ee2222ec20b86e16ca8f',
    });

    console.log('🔺', NFTs);
  } catch (error) {
    console.error(error);
  }
}

bootstrap();

Using const Moralis = require(moralis/node) seems to « solve » this issue, but I was wondering if there was a proper way of importing Moralis’ SDK with ES6 imports.

This is still a problem. I too am using NestJS as my backend, and all forms of ES6 import causes Moralis to be undefined. I think this is some kind of issue with the way the export is defined.