Skip to content

Support adding .js extensions to all exports (except root) #898

@jpzwarte

Description

@jpzwarte

Clear and concise description of the problem

https://nodejs.org/api/packages.html#extensions-in-subpaths

That mentions import maps and adding .js extensions to your package exports. There currently is no config option to enable this in tsdown. I was able to add this myself by having a customExports callback:

exports: {
    devExports: true,
    customExports(exports) {
      return Object.fromEntries(
        Object.entries(exports).map(([key, value]) => {
          if (key === '.' || /\.[^/]+$/.test(key)) {
            return [key, value];
          }

          return [`${key}.js`, value];
        })
      );
    }
  },

Suggested solution

Please expand the exports config option to support this.

Alternative

Write your own customExports callback as shown above.

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority

    None yet

    Start date

    None yet

    Target date

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions