Skip to content

Incorrect mkdist resolve relative imports with several entries #544

@alSergey

Description

@alSergey

Environment

Reproduction

  • Open StackBlitz
  • Run npx unbuild
  • Inspect the output files:
    • dist/common/fn.js (all correctly transformed)
    • dist/runtime/fn.js (import from src/common/ wasn't transformed)

Describe the bug

mkdist has built-in functionality for resolving relative imports, and it works great. You can see this in the dist/common/fn.js file.

import { COMMON_CONFIG } from "./config/index.js"; // correctly transformed
export const getConfig = () => {
  return COMMON_CONFIG;
};

Unfortunately, this functionality doesn't work when multiple entries are specified. This is evident in the dist/runtime/fn.js file. In that file, the import from src/runtime/ is correctly transformed, but the import from src/common/ remains unchanged.

import { COMMON_CONFIG } from "../common/config"; // wasn't transformed
import { RUNTIME_CONFIG } from "./config/index.js"; // correctly transformed
export const getCommonConfig = () => {
  return COMMON_CONFIG;
};
export const getRuntimeConfig = () => {
  return RUNTIME_CONFIG;
};

Is there a way to configure unbuild so that it properly resolves extensions when using multiple entries?

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions