Skip to content

resolveId hook importer inconsistent in pre stage #5981

@DylanPiercey

Description

@DylanPiercey

Describe the bug

If using the resolveId(importee, importer, opts) hook with enforce: "pre", the importer will be different in dev mode vs in build mode.

Specifically in dev mode the importer will always be the top level .html file.
For my specific use case this makes it impossible to determine what the top level scripts are without other work arounds.

I was thinking ideally I'd be able to do:

resolveId(importee, importer) {
  if (importer) {
    if (this.getModuleInfo(importer).isEntry) {
        // This tells me that the parent of importee` is the top level file, the `.html` file.
    }
  }
}

However using isEntry on getModuleInfo also only works in build mode.

Reproduction

See https://github.com/DylanPiercey/vite-issue-resolve-id-repro

System Info

System:
    OS: macOS 10.15.7
    CPU: (4) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
    Memory: 3.43 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 16.6.2 - ~/.nvm/versions/node/v16.6.2/bin/node
    Yarn: 1.22.5 - ~/.yarn/bin/yarn
    npm: 7.20.3 - ~/.nvm/versions/node/v16.6.2/bin/npm
  Browsers:
    Chrome: 95.0.4638.69
    Edge: 96.0.1054.43
    Firefox: 91.0
    Safari: 15.1

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions