Skip to content

import is not replaced with resolved id for external dynamic import #1723

@hi-ogawa

Description

@hi-ogawa

Reproduction link or steps

This is probably a minimal repro of playground/dynamic-import test failure vitejs/rolldown-vite#28 (comment).

It looks like when dynamic import is externalized, import is not replaced with resolved id

https://github.com/hi-ogawa/rolldown/blob/df7ddac3642827eb8e20846c11ca6bd8352c1e3d/examples/repro-dynamic-css

  • src/entry.js
import "./static.css";
import("./dynamic.css");
  • index.js
import * as rolldown from "rolldown";
import path from "node:path";

async function main() {
  const bundle = await rolldown.rolldown({
    cwd: import.meta.dirname,
    input: "src/entry.js",
    plugins: [
      {
        name: "external-css",
        resolveId(id, importer) {
          if (id.endsWith(".css")) {
            const resolved = path.resolve(importer, "..", id);
            console.log({ id, importer, resolved });
            return {
              id: resolved,
              external: true,
            }
          }
        }
      }
    ]
  });
  await bundle.write({
    format: "esm",
  });
  process.exit(0);
}

main();
  • dist/entry.js
import "/home/hiroshi/code/others/rolldown/examples/repro-dynamic-css/src/static.css";

//#region src/entry.js
import("./dynamic.css");

//#endregion

What is expected?

dist/entry.js should be

import "/home/hiroshi/code/others/rolldown/examples/repro-dynamic-css/src/static.css";
import("/home/hiroshi/code/others/rolldown/examples/repro-dynamic-css/src/dynamic.css");

What is actually happening?

dist/entry.js is

import "/home/hiroshi/code/others/rolldown/examples/repro-dynamic-css/src/static.css";
import("./dynamic.css");

System Info

System:
    OS: Linux 6.9 Arch Linux
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-12650H
    Memory: 21.94 GB / 31.06 GB
    Container: Yes
    Shell: 5.2.26 - /usr/bin/bash
  Binaries:
    Node: 20.14.0 - ~/.volta/tools/image/node/20.14.0/bin/node
    npm: 10.7.0 - ~/.volta/tools/image/node/20.14.0/bin/npm
    pnpm: 9.5.0 - ~/.volta/tools/image/node/20.14.0/bin/pnpm
  Browsers:
    Chromium: 126.0.6478.126
  npmPackages:
    rolldown: workspace:* => 0.12.2

Any additional comments?

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions