Description
Description
I hope such new conditional option would benefit developers using Vite and some dependencies built from tools that does not support "exports" field yet.
My situation
This is a simplified model from my real project.
My project depends on a
and a
depends on b
. Although b
has exports
field, a
is still building with out-of-date toolchain that does not know about exports
field, so a
resolves b/dist/subpath/index.js
without problem. If a
respected exports
field, it would have to import b/subpath/index.js
instead.
My NPM package
{
"dependencies": {
"a": "^1.0.0"
},
"devDependencies": {
"vite": "latest"
}
}
// index.js
import "a";
NPM package a
{
"name": "a",
"module": "dist/index.js",
"dependencies": {
"b": "^1.0.0"
}
}
// dist/index.js
import "b/dist/subpath/index.js";
NPM package b
{
"name": "b",
"module": "./dist/index.js",
"exports": {
"./*.js": "./dist/*.js"
}
}
I got such error from Vite:
✘ [ERROR] Could not resolve "b/dist/subpath/index.js"
node_modules/a/dist/index.js:
│ import 'b/dist/subpath/index.js';
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The module "./dist/dist/subpath/index.js" was not found on the file system:
node_modules/b/package.json:
│ "./*.js": "./dist/*.js",
╵ ~~~~~~~~~~~~~~~~~~
You can mark the path "b/dist/subpath/index.js" as external to exclude it from the bundle,
which will remove this error and leave the unresolved path in the bundle.
Suggested solution
I know there is a trend to use exports
field and it really is beneficial in many ways. I do use to in my package as well! But in this situation, this becomes a blocker from using Vite.
Perhaps adding a new option to allow fallback to ignore resolution error of exports
field, e.g. resolve.bearExportsError
. When it is true
, do not throw error from
vite/packages/vite/src/node/plugins/resolve.ts
Line 1038 in d0221cd
I am not experienced in designing build tools so here my suggestion might be really naive. Hope I have clarified my situation well and you could figure out a better idea for this problem.
Thanks in advance!
Alternative
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.