Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building with esnext target causes server to not be runnable #179

Open
lithdew opened this issue Feb 2, 2024 · 5 comments
Open

Building with esnext target causes server to not be runnable #179

lithdew opened this issue Feb 2, 2024 · 5 comments

Comments

@lithdew
Copy link

lithdew commented Feb 2, 2024

I was looking to use top-level await in my application which appears to only be available on targets ES2022/ESNext. The server built by default targets ES2019.

app.config.ts:

import { TanStackRouterVite } from "@tanstack/router-vite-plugin";
import reactRefresh from "@vitejs/plugin-react";
import { createApp } from "vinxi";

export default createApp({
    routers: [
        {
            name: "public",
            type: "static",
            dir: "./public",
            base: "/",
        },
        {
            name: "trpc",
            type: "http",
            handler: "./src/entry-trpc.tsx",
            target: "server",
            base: "/trpc",
        },
        {
            name: "ssr",
            type: "http",
            handler: "./src/entry-server.tsx",
            target: "server",
            plugins: () => [reactRefresh(), TanStackRouterVite()],
        },

        {
            name: "client",
            type: "client",
            handler: "./src/entry-client.tsx",
            target: "browser",
            plugins: () => [reactRefresh(), TanStackRouterVite()],
            base: "/_build",
        },
    ],
    server: {
        esbuild: {
            options: {
                target: "es2022",
            }
        },
        experimental: {
            asyncContext: true,
        },
    },
});

Running node .output/server/index.mjs on the built output causes the server to exit immediately on startup. I am using Node v18.16. In dev mode, the application runs fine.

@nksaraf
Copy link
Owner

nksaraf commented Feb 2, 2024

Any error messages or logs ? Need more info

@lithdew
Copy link
Author

lithdew commented Feb 3, 2024

Any error messages or logs ? Need more info

There appears to be no error messages or logs.

Here's a reproduction: https://stackblitz.com/edit/vinxi-test?file=src%2Frouter.tsx

The top-level await happens in src/router.tsx in export const trpc = ....

Run npm run build && node .output/server/index.mjs and the server will immediately close on startup.

Running npm run dev however works.

@shiro
Copy link

shiro commented Feb 5, 2024

I'm also able to run my solid start project in dev, but building and running production just exits without any message.

@AlexErrant
Copy link

Is this an esbuild limitation? evanw/esbuild#253

@fgsreally
Copy link

in my case.when set target to esnext or support top-level-await,it can build but can't start
error is:

File URL path must be absolute    

look at compiled code

globalThis._importMeta_=globalThis._importMeta_||{url:"file:///_entry.js",env:process.env};
//...
var __filename = fileURLToPath(globalThis._importMeta_.url);

it seems that esbuild doesn't handle import.meta correctly

even if I set import-meta to true ,it doesn't work esbuild_supported

const serverConfig = {
  esbuild: {
    options: {
      supported: {
        'top-level-await': true,
        'import-meta': true,
      },
    },
  },
}

I remove all import.meta in source code and now it work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants