vite-plugin-node icon indicating copy to clipboard operation
vite-plugin-node copied to clipboard

vite ssr import 2 is not a function

Open tomdavidson opened this issue 2 years ago • 1 comments

No error on build but when I make a request with the dev server, I get __vite_ssr_import_2__ is not a function in the console and the web browser never receives a response. Any ideas?

Basic app:

export const dispatcherApp = (req, res) => {
  const app = express();

  app.get("/", (req, res) => {
    res.send("change me to see updates, cloud functions!!");
  });

  app(req, res);
};

Config:

export default defineConfig({
  server: {
    port: 3000,
  },
  build: { ssr: false },
  plugins: [
    ...VitePluginNode({
      adapter: "express",
      appPath: "./src/index.ts",
      exportName: "dispatcherApp",
      tsCompiler: "swc",
    }),
  ],
});

tomdavidson avatar Feb 22 '23 00:02 tomdavidson

I solved this by changing imports from import * as express from 'express' to import express from 'express'.

JohnGurin avatar Jun 11 '23 15:06 JohnGurin