Skip to content

import fails to resolve when using esbuild build tool #24593

@wang1212

Description

@wang1212

Is your feature request related to a problem? Please describe.

When using the esbuild build tool, the import statement reports an error that cannot be resolved.

E.g:

import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';

This is because of the following configuration:

"exports": {
  "./examples/jsm/*": "./examples/jsm/*"
}

Although tools like rollup, webpack, etc. may be normal, obviously esbuild respects node specification standards more.

According to the node specification, in order for the esbuild tool to work properly, the file extension needs to be added:

import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';

Obviously when this happens, many people need to spend as much time as I do to analyze the cause of the problem.

In fact, the following configuration can also solve the problem:

"exports": {
  "./examples/jsm/*": "./examples/jsm/*.js" 
}

In order to improve development efficiency (compilation speed), esbuild should have been widely used, can this problem be solved?

see also evanw/esbuild#2518

Describe the solution you'd like

  1. For files of the same type (such as .js), change the exports configuration in package.json, for example
"exports": {
  "./examples/jsm/*": "./examples/jsm/*.js"
}
  1. For different categories of files contained in a folder, multiple configurations can be written, or it is clearly mentioned in the documentation that developers should write extensions when importing?
"exports": {
  "./examples/jsm/*.js": "./examples/jsm/*.js",
  "./examples/jsm/*.png": "./examples/jsm/*.png"
}

Describe alternatives you've considered

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions