`import` fails to resolve when using `esbuild` build tool
See original GitHub issueIs 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 https://github.com/evanw/esbuild/issues/2518_
Describe the solution you’d like
- For files of the same type (such as
.js
), change theexports
configuration in package.json, for example
"exports": {
"./examples/jsm/*": "./examples/jsm/*.js"
}
- 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
Issue Analytics
- State:
- Created a year ago
- Comments:32 (14 by maintainers)
Top GitHub Comments
I thought omitting the .js extension on imports was mostly a TypeScript-ism, is it used outside TS?
I don’t think we should be doing that anywhere within this project, including examples…
If you’d like esbuild to be more flexible in its ability to resolve package paths I recommend making an issue or PR to the esbuild project rather than one here. But either way it is not common for packages to export files in the style you have recommended. And as you’ve mentioned this kind of export can lead to file ambiguity. It’s best to explicitly import the files you want to your project. You can see that even
react-dom
does not export files in a way that affords dropping the file extension.