Skip to content

TypeError: esbuild.serve is not a function #3421

Closed as not planned
Closed as not planned
@mebest100

Description

@mebest100

I have react project based on Wepack and now want to migrate to esbuild entirely.

But when I ran it on a dev server, esbuild report " TypeError: esbuild.serve is not a function"

below is the config , pls tell me what's wrong with it? Thx!

`const esbuild = require("esbuild");
const lessPlugin = require("esbuild-plugin-less").lessPlugin;
const cssModulesPlugin = require("esbuild-plugin-css-modules").cssModulesPlugin;

const alias = require("esbuild-plugin-alias");

const path = require("path");
const port = 7002;

(async () => {
const {babel} = await import("esbuild-plugin-babel");
const { htmlPlugin } = await import("@chialab/esbuild-plugin-html");

const config = {
entryPoints: ["./public/index.html"],
bundle: true,
outdir: "./public",
define: {
"process.env.NODE_ENV": '"development"',
},
minify: false,
splitting: true,
loader: {
".js": "jsx",
".css": "css",
".less": "less",
".png": "file",
".jpg": "file",
".jpeg": "file",
".gif": "file",
".svg": "file",
},
plugins: [
babel,
cssModulesPlugin,
lessPlugin,
htmlPlugin,
alias({

    "@": path.resolve(__dirname, "./src"),
  }),
],

};

esbuild
.serve(
{
servedir: "public",
port,
},
config
)
.then(() => {
console.log(Development server is running on http://localhost:${port});
})
.catch(() => process.exit(1));
})();`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions