Skip to content

Plugin loader: derive id from parent directory when module basename is generic (plugin.js/index.js) #596

Closed

Description

@melvincarvalho

What happens

The loader derives a plugin's id from the module basename. The natural out-of-tree convention is <name>/plugin.js, so every plugin derives the id plugin, and the (correct) duplicate-id guard refuses to boot until each entry carries an explicit id.

Repro

createServer({ plugins: [
  { module: 'relay/plugin.js', prefix: '/relay' },
  { module: 'webrtc/plugin.js', prefix: '/webrtc' },
] })
// → duplicate plugin id 'plugin'

Evidence

All 32 plugins in https://github.com/JavaScriptSolidServer/plugins hit this; compose.test.js and serve.js there carry 32 hand-written id: fields solely to dodge it. See REPORT.md ("Five loader/core bugs", #1).

Suggested fix

When the basename is generic (plugin, index), derive the id from the parent directory: relay/plugin.js → relay. Backward-compatible (explicit id still wins); removes the most common plugin-author footgun.

Activity

  1. added
    bug
    plugin
    on Jul 11, 2026
  2. melvincarvalho commented on Jul 11, 2026

    @melvincarvalho
    ContributorAuthor

    Sharpened while dogfooding: this doesn't just annoy config authors — it blocks the --plugin CLI entirely for any repo using the <name>/plugin.js convention.

    Concrete repro, loading two plugins from the out-of-tree plugins repo (where every plugin is <name>/plugin.js):

    jss start --plugin ./relay/plugin.js@/relay --plugin ./dashboard/plugin.js@/dashboard
    # Error: plugins: duplicate id 'plugin' — set entry.id to keep the plugins' data dirs apart

    Both basenames reduce to the id plugin → collision on the second flag. And the --plugin <module[@prefix]> flag has no field to set an explicit id (unlike createServer({ plugins }) / a config file, where you can). So the fix suggested here — derive the id from the parent directory when the basename is generic (plugin, index) — isn't just ergonomics: it's what makes the CLI usable at all for the conventional layout. With it, ./relay/plugin.js → relay, ./dashboard/plugin.js → dashboard, and the bare --plugin form Just Works.

    Today the workaround is the explicit-id form only:

    { "plugins": [
      { "id": "relay",     "module": "./relay/plugin.js",     "prefix": "/relay" },
      { "id": "dashboard", "module": "./dashboard/plugin.js", "prefix": "/dashboard" }
    ] }

    i.e. a config file or createServer(...) — the CLI --plugin flag can't reach it. All 33 plugins in the plugins repo hit this; it's why they're loaded via serve.js (explicit ids) rather than jss --plugin.

  3. added a commit that references this issue on Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugplugin

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions