Moralis and Firebase error

Hi folks, I have a tricky error that im stuck with which I will try to explain and its maybe a long shot.

Im using Moralis inside google cloud functions with firebase and im using Moralis version 2.12.0 ( latest ). My issue is when i run locally or deploy to firebase i get the following error:

functions: Failed to load function definition from source: FirebaseError: Failed to load function definition from source: Failed to generate manifest from function source: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath ‘./.’ is not defined by “exports” in /Users//functions/node_modules/moralis/package.json

Im importing the moralis package as follows: const Moralis = require(‘moralis’).default;

Would anyone be able to shed any light on this?

Hey can we have more details how your code looks like inside the Firebase Cloud Functions?

It should have worked as we have a demo for calling eh Web3 APIs here https://docs.moralis.io/web3-data-api/integrations/firebase-advanced-nodejs

For Auth and Streams, there’s also Firebase extension to integrate Moralis easily :grinning_face_with_smiling_eyes:

1 Like

Hi there for sure, please see below how the code is structured, and thanks again for the help, much appreciated.

import {Request, Response} from "express";
import * as functions from "firebase-functions";

const  Moralis = require('moralis');

const getNFTs = async (req: Request, res: Response) => {
  try {

    const requestMessage = {
        walletAddress: req.query.walletAddress,
        chain: req.query.chain,
    };

    if (!requestMessage) {
      res.status(404).send('NFT object not found');
      return;
    }
    if (!requestMessage.walletAddress) {
      res.status(404).send('NFT Wallet object not found');
      return;
    }

    if (!requestMessage.chain) {
      res.status(404).send('Chain object not found');
      return;
    }

    const api_key = functions.config().moralis.api_key;

    if (!Moralis.Core.isStarted) {
      await Moralis.start({
        apiKey: ?????,
        logLevel: 'error',
        formatEvmAddress: 'checksum',
        formatEvmChainId: 'decimal'
      });
    }

    const response = await Moralis.EvmApi.nft.getWalletNFTs({
        address: requestMessage.walletAddress, 
        chain: requestMessage.chain, 
        normalizeMetadata: true
    });
    

    if (response.result.length > 0) {
        return res.status(200).json(response.result);
    }
    
    return res.status(200).json('No Content')
   
  } catch (error) {
    // @ts-ignore
    return res.status(500).json(error.message);
  }
}

export { getNFTs }

Then when the app runs i get the following error:

functions: Failed to load function definition from source: FirebaseError: Failed to load function definition from source: Failed to generate manifest from function source: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath ‘./.’ is not defined by “exports” in /Users//functions/node_modules/moralis/package.json

I believe it could be to do with the exports section inside the moralis package.json

Any help would be great

Not exact sure if this is causing the error but you can use import statement to import Moralis as you are already using import for other packages

import Moralis from "moralis";

If in case your code is exported from index.js of the firebase function then try exporting the function like this. This worked for me in the past for exporting firebase HTTP functions.

module.exports = {
 functionName : functions.https.onRequest(getNFTs), 
}

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.