Support `package.json` `"exports"` when resolving `tstl.luaPlugins` · Issue #1731 · TypeScriptToLua/TypeScriptToLua · GitHub
Skip to content

Support package.json "exports" when resolving tstl.luaPlugins #1731

Open

Description

@jiwonz

luaPlugins tstl option with name field currently cannot resolve plugin packages that rely on package.json "exports" subpath mappings.

Example tsconfig:

{
  "tstl": {
    "luaPlugins": [
      {
        "name": "my-package/plugins"
      }
    ]
  }
}

This fails with a plugin resolution diagnostic like:

Could not resolve "my-package/plugins" plugin from "...".

However, the package is valid and works with Node resolution:

require("my-package/plugins")

I doubt because resolve library that currently tstl is using is old and unable to resolve the plugin package via package.json's "exports" properly

https://github.com/TypeScriptToLua/TypeScriptToLua/blob/master/src/transpilation/utils.ts#L54

resolved = resolve.sync(query, { basedir, extensions: [".js", ".ts", ".tsx"] });

Activity

  1. Perryvw commented on Jul 13, 2026

    @Perryvw
    Member

    What does the plugin with exports mapping look like, and why does it need to use it? Why is the plugin not just resolvable by generic means?

  2. jiwonz commented on Jul 13, 2026

    @jiwonz
    Author

    What does the plugin with exports mapping look like, and why does it need to use it? Why is the plugin not just resolvable by generic means?

    Sorry for missing/less informations. The package exports look like:

    {
      "exports": {
        "./plugins": {
          "types": "dist/plugins.d.ts",
          "default": "dist/plugins.js"
        }
      }
    }

    And i need to use "exports" to achieve these:

    • one package containing and exporting multiple plugins
    • in my case, i need to export plugin in specific route to export various other necessary features for the package user such as macro types, tsconfig files etc
    • package encapsulation (very common and quite necessary)
    • "exports" field is more modern and regarded feature than "main"

    BTW, there was a workaround by adding like plugins.js file that routes/re-exports the exports of dist/plugins.js (which is the way of fallback for commonjs/legacy)

  3. pilaoda commented on Jul 20, 2026

    @pilaoda
    Contributor

    Duplicated?
    #1389

  4. jiwonz commented on Jul 20, 2026

    @jiwonz
    Author

    Duplicated? #1389

    Oh seems like there was an issue which was written very long time ago but it looks like related but mentioned very poorly especially about the luaPlugins at its second problem. That issue seems mainly talking about module resolution to me rather focused especially on the tstl lua plugins. So i'm bit not sure is it actually duplicated.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions