AstroJS - "esbuild" should be marked as external

Hey there, this is my site: https://niklas-prod.netlify.app/

We’re trying to get Netlify SSR (we need it for making calls to the Ghost CMS API) to work with AstroJS. In the deploy log we’re getting:

10:58:13 PM:   2. Functions bundling                                         
10:58:13 PM: ────────────────────────────────────────────────────────────────
10:58:13 PM: ​
10:58:13 PM: Packaging Functions from .netlify/functions-internal directory:
10:58:13 PM:  - entry.mjs
10:58:13 PM: ​
10:58:13 PM: ▲ [WARNING] "esbuild" should be marked as external for use with "require.resolve"
10:58:13 PM:     node_modules/esbuild/lib/main.js:1727:36:
10:58:13 PM:       1727 │   const libMainJS = require.resolve("esbuild");
10:58:13 PM:            ╵                                     ~~~~~~~~~
10:58:14 PM: ​
10:58:14 PM: ❯ Functions bundled with warnings:
10:58:14 PM:    - entry.zip
10:58:14 PM: ​
10:58:14 PM: ❯ The following Node.js modules use dynamic expressions to include files:
10:58:14 PM:    - i18next-fs-backend
10:58:14 PM:    - tsm
10:58:14 PM:    - @proload/core
10:58:14 PM: ​
10:58:14 PM:   Because files included with dynamic expressions aren't bundled with your serverless functions by default,
  this may result in an error when invoking a function. To resolve this error, you can mark these Node.js
10:58:14 PM:   modules as external in the [functions] section of your `netlify.toml` configuration file:
10:58:14 PM: ​
10:58:14 PM: Starting post processing
10:58:14 PM:   [functions]
10:58:14 PM:     external_node_modules = ["i18next-fs-backend", "tsm", "@proload/core"]
10:58:14 PM: ​
10:58:14 PM: Post processing - HTML
10:58:14 PM:   Visit https://ntl.fyi/dynamic-imports for more information.
10:58:14 PM: ​
10:58:14 PM: ​
10:58:15 PM: Post processing - header rules
10:58:14 PM: (Functions bundling completed in 1s)
10:58:14 PM:

And indeed the entry function is currently throwing this error in the deployed site:

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined
    at new NodeError (node:internal/errors:387:5)
    at createRequire (node:internal/modules/cjs/loader:1315:11)
    at Object.<anonymous> (/var/task/.netlify/functions-internal/entry.js:50433:48)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
    at Module.load (node:internal/modules/cjs/loader:1074:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12)
    at Module.require (node:internal/modules/cjs/loader:1098:19)
    at require (node:internal/modules/cjs/helpers:108:18)
    at Object.<anonymous> (/var/task/entry.js:1:18)

Complete newbie here so would be awesome if someone could explain why esbuild needs to be marked as external and how this can be achieved with AstroJS. Thanks a bunch!

Not sure why you need to bundle esbuild with your function code? Maybe you’ve a rogue dependency that’s doing this?

In any case, a minimal reproduction would be needed to guess any further than that.

I was hoping you might tell me :smiley:

No idea what esbuild is and why it’s bundled in here. This is our AstroJS config:

import { defineConfig } from "astro/config";
import tailwind from "@astrojs/tailwind";
import compress from "astro-compress";
import astroI18next from "astro-i18next";
import image from "@astrojs/image";
import netlify from "@astrojs/netlify/functions";

// https://astro.build/config
export default defineConfig({
output: "server",
adapter: netlify(),
integrations: [
astroI18next(),
tailwind({
config: {
path: "./tailwind.config.cjs",
},
}),
compress({
css: true,
html: true,
img: false,
js: true,
svg: false,
}),
image({
serviceEntryPoint: "@astrojs/image/sharp",
logLevel: "debug",
}),
],
});

Leading to the warning above, and to this error at run time: https://master--niklas-prod.netlify.app/

I was hoping you might tell me. :smiley:

No idea what esbuild is and why it’s being bundled here! This is our AstroJS config:

import { defineConfig } from "astro/config";
import tailwind from "@astrojs/tailwind";
import compress from "astro-compress";
import astroI18next from "astro-i18next";
import image from "@astrojs/image";
import netlify from "@astrojs/netlify/functions";

// https://astro.build/config
export default defineConfig({
output: "server",
adapter: netlify(),
integrations: [
astroI18next(),
tailwind({
config: {
path: "./tailwind.config.cjs",
},
}),
compress({
css: true,
html: true,
img: false,
js: true,
svg: false,
}),
image({
serviceEntryPoint: "@astrojs/image/sharp",
logLevel: "debug",
}),
],
});```

Leading to the warning above and to this error at run time: https://master--niklas-prod.netlify.app/

Hm, I just replied to this twice but I think my posts are getting spam-filtered because I included a link to the website :smiley:

Also, I was trying to Netlify-SSO into the forum so it may come from a different account. If a moderator could kindly approve my reply!

Or anyway trying again from this account:

@hrishikesh
I was hoping you might tell me. :smiley:

No idea what esbuild is and why it’s being bundled here! This is our AstroJS config:

import { defineConfig } from "astro/config";
import tailwind from "@astrojs/tailwind";
import compress from "astro-compress";
import astroI18next from "astro-i18next";
import image from "@astrojs/image";
import netlify from "@astrojs/netlify/functions";

// https://astro.build/config
export default defineConfig({
output: "server",
adapter: netlify(),
integrations: [
astroI18next(),
tailwind({
config: {
path: "./tailwind.config.cjs",
},
}),
compress({
css: true,
html: true,
img: false,
js: true,
svg: false,
}),
image({
serviceEntryPoint: "@astrojs/image/sharp",
logLevel: "debug",
}),
],
});```

Leading to the warning above and to this error at run time: https://master--niklas-prod.netlify.app/

Hi @niklas1 ,

Your posts came through :ok_hand: there’s actually duplicates :slight_smile:

esbuild is a fast JavaScript bundler and minifier that can be used to optimize bundling time and artifact size for your JavaScript functions in Netlify. It’s enabled by adding the following configuration to your netlify.toml file:

[functions]
  node_bundler = "esbuild"

As Hrishikesh mentioned, a minimal reproduction would be needed for us to debug your case further.

What is minimal reproduction?

A minimal reproduction is a simplified version of your project that demonstrates the issue you’re facing. It should contain the least amount of code and dependencies necessary to reproduce the problem. Creating a minimal reproduction helps others understand the issue more easily and assists in debugging and finding solutions.