Netlify don't start since adding mongo

Hello,

I get a problem since I add mongo db to my netlify function.

 [ERROR] No loader is configured for ".node" files: ../../../node_modules/@napi-rs/snappy-darwin-arm64/snappy.darwin-arm64.node

    ../../../node_modules/snappy/index.js:1:2291:
      1 │ ...ding=require("./snappy.darwin-arm64.node"):nativeBinding=require("@napi-rs/snappy-darwin-arm64")}catch(e){loadError=e}break;default:throw new Error(`Unsupporte...
        ╵    

My function :

import { Handler } from "@netlify/functions";
const { MongoClient} = require("mongodb");
//require('dotenv').config();

const handler: Handler = async (event, context) => {
    // your server-side functionality
    console.log("let's check order at faire");
    const mongoClient = new MongoClient("mongodb+srv://ms_dev:pwd_ms_dev@cluster0.gcezcdz.mongodb.net/?retryWrites=true&w=majority");
    const clientPromise = mongoClient.connect();

    try {
        const database = (await clientPromise).db("fairedata");
        const collection = database.collection("order");
        const result = await collection.find({}).limit(10).toArray();
        return {
            statusCode: 200,
            body: JSON.stringify(result),
        };
    } catch (error) {
        return {
            statusCode: 500,
            body: JSON.stringify({ message: "Internal Server Error " }),
        }
    }
 
};

export { handler };

My package.json

"dependencies": {
    "@netlify/functions": "^1.3.0",
    "mongodb": "4.11"
  }

My netlify.toml

[functions."check-order"]
schedule = "@hourly"

I don’t find anything on internet. And I get this since I added mongo

Regard,

1 Like

My node js version is
Node.js v18.7.0

1 Like

Can you share your project? It seems you’re using Webpack somewhere (as the error you shared seems o be the kind that Webpack throws).

i sent you an invitation

I tried and can’t seem to reproduce the problem. I cloned the dev branch and was easily able to start netlify dev. Could you try using Node 16?

Update the netlify-cli package to the last version and adding

[functions]
    node_bundler = "esbuild"

to the toml fix my problem. May be that just the update was necessary. npm i netlify-cli

Thank you very much

Thanks for coming back and sharing! Glad you got everything working :rocket:

2 Likes