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

Incorrect order of imports after bundling #2983

Open
fabiospampinato opened this issue Mar 11, 2023 · 2 comments
Open

Incorrect order of imports after bundling #2983

fabiospampinato opened this issue Mar 11, 2023 · 2 comments

Comments

@fabiospampinato
Copy link

Here's a repro. npm i && npm run dev to see the error.

Basically inside ./server/index.tsx I have the following:

import 'linkedom-global'; //TODO: Delete this dependency
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import {favicon, serveStatic} from 'noren/middlewares';
import Server from 'noren/node';
import livereload from 'tiny-livereload/express';
import {renderToString} from 'voby';
import {useRouter} from 'voby-simple-router';
import Routes from '../src/app/routes';
import App from '../src/app';

Where the order of those imports is significant, because first of all I'm shimming the DOM by loading linkedom-global, which other things will subsequently rely upon.

The problem is that after bundling that code (npm run dev:bundle:server to just bundle that file), the order imports changes, which is the bug in question, which in this case breaks my app.

var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __esm = (fn, res) => function __init() {
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
};
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};

// src/pages/loader.tsx
var loader_exports = {};
__export(loader_exports, {
  default: () => loader_default
});
import { Suspense } from "voby";
import { useLoader } from "voby-simple-router";
import { jsx as jsx4, jsxs as jsxs4 } from "voby/jsx-runtime";
var PageLoader, loader_default;
var init_loader = __esm({
  "src/pages/loader.tsx"() {
    PageLoader = () => {
      const resource = useLoader();
      const value = () => resource().value;
      return /* @__PURE__ */ jsx4(Suspense, { fallback: /* @__PURE__ */ jsx4("h1", { children: "Loading..." }), children: /* @__PURE__ */ jsxs4("h1", { children: [
        "Loaded: ",
        value
      ] }) });
    };
    loader_default = PageLoader;
  }
});

// server/index.tsx
import "linkedom-global";
import fs from "node:fs";
import path from "node:path";
import process from "node:process";
import { favicon, serveStatic } from "noren/middlewares";
import Server from "noren/node";
import livereload from "tiny-livereload/express";
import { renderToString } from "voby";
import { useRouter } from "voby-simple-router";

For whatever reason some imports now happen before the linkedom-global import.

@evanw
Copy link
Owner

evanw commented Mar 11, 2023

I believe the problem in this case is caused by the dynamic import(). A quick workaround could be to convert the dynamic import() expression into a static import statement. I'll try to work fixing this bug into the eventual linker rewrite that I need to do for esbuild.

@fabiospampinato
Copy link
Author

Yes removing the dynamic import doesn't trigger this error. But in general I can't just give up dynamic imports.

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

2 participants