remix-run / remix

Build Better Websites. Create modern, resilient user experiences with web fundamentals.
https://remix.run
MIT License
29.94k stars 2.52k forks source link

Remix build is not in the order it was imported #5848

Open woody146 opened 1 year ago

woody146 commented 1 year ago

What version of Remix are you using?

1.14.3

Are all your remix dependencies & dev-dependencies using the same version?

Steps to Reproduce

Import "reflect-metadata" at first line of root.tsx

import "reflect-metadata";
import type { MetaFunction } from "@remix-run/node";
import {
  Links,
  LiveReload,
  Meta,
  Outlet,
  Scripts,
  ScrollRestoration,
} from "@remix-run/react";

export const meta: MetaFunction = () => ({
  charset: "utf-8",
  title: "New Remix App",
  viewport: "width=device-width,initial-scale=1",
});

export default function App() {
  return (
    <html lang="en">
      <head>
        <Meta />
        <Links />
      </head>
      <body>
        <Outlet />
        <ScrollRestoration />
        <Scripts />
        <LiveReload />
      </body>
    </html>
  );
}

Expected Behavior

I want to remix create the code of reflect-metadata first in the code

Actual Behavior

But I check the root.js file in public/build/, the result is as follows

import {
  Links,
  LiveReload,
  Meta,
  Outlet,
  Scripts,
  ScrollRestoration
} from "/build/_shared/chunk-L5I5ERLF.js";
import {
  __toESM,
  require_jsx_dev_runtime
} from "/build/_shared/chunk-EETRBLDB.js";

// node_modules/reflect-metadata/Reflect.js
var Reflect;
(function(Reflect2) {
  (function(factory) {
    var root = typeof globalThis === "object" ? globalThis : typeof self === "object" ? self : typeof this === "object" ? this : Function("return this;")();
    var exporter = makeExporter(Reflect2);
    if (typeof root.Reflect === "undefined") {
      root.Reflect = Reflect2;
    } else {
....

reflect-metadata's code was added later so my code got error reflect.getmetadata is not a function

DanielSchiavini commented 1 year ago

Is there any preview when this bug will be fixed? I'm trying to migrate an existing app to Remix and reflect-metadata is going to be necessary

pcattori commented 1 year ago

This is a limitation of esbuild. See https://github.com/evanw/esbuild/issues/399

willin commented 12 months ago

seems that esbuild supports metadata https://github.com/airplanedev/lib/pull/534