Skip to content

correct exports of extensionless imports #26924

@jgaardsted

Description

@jgaardsted

Description

The exports field in three.js package.json is incorrectly specified.
It is specified like this, and missing the .js extensions on the right hand side:
(I should probably file this as reproducible bug instead of as a feature request)

{
  "exports": {
    ".": {
      "import": "./build/three.module.js",
      "require": "./build/three.cjs"
    },
    "./examples/fonts/*": "./examples/fonts/*",
    "./examples/jsm/*": "./examples/jsm/*",
    "./addons/*": "./examples/jsm/*",
    "./src/*": "./src/*",
    "./nodes": "./examples/jsm/nodes/Nodes.js"
  },
}

Solution

The solution is to correctly specify them like this:

{
  "exports": {
    "./examples/jsm/*": "./examples/jsm/*.js",
    "./addons/*": "./examples/jsm/*.js",
    "./src/*": "./src/*.js",
  }
}

Alternatives

Currently, this must be worked around with a bundler that alleviates this with some sort of aliasing mechanism,
like vite. But it is unfortunate that this issue dictates which bundlers can/can't be used.

Additional context

The issue is discussed on stackoverflow in detail here:
https://stackoverflow.com/questions/77237284/getting-rollup-to-resolve-extensionless-imports-in-node-modules-for-browser-bund/77244840#77244840

I should probably figure out how to file this bug as a proper reproducible bug instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions