Can not resolve when package.json exports field resolution result is a direcory
See original GitHub issueDescribe the bug
I have a package named some-package
and it’s files are in node_modules
.
package.json
in node_modules/some-package
{
"name": "some-package",
"version": "1.0.0",
"license": "MIT",
"exports": {
".": "./index.js",
"./sub": "./lib/sub"
}
}
index.js
in node_modules/some-packages/lib/sub
export const Foo = 'Foo';
then I import it in the main.js
in root directory
import { Foo } from 'some-package/sub';
console.log(Foo);
it complain the error
I also run the same code in Node.js or Webpack-based project, they can correctly resolve some-package/sub
In previous issue #7267 I know how to fix it. I’m willing to submit a PR with well-tested code❤️ if Vite team think it’s a bug
Reproduction
https://stackblitz.com/edit/vitejs-vite-cz6tvn?file=main.js
System Info
I don't know the system info in Stackbliz. But this issue is not platform-related I think
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Unable to resolve modules specified in package.json's " ...
I'm working on a JS web application and am trying to use the exports field in a package.json file to clean up the...
Read more >https://nodejs.org/api/modules.md
If X does not match this pattern or DIR/NAME/package.json is not a file, return. 3. Parse DIR/NAME/package.json, and look for "exports" field. 4....
Read more >rollup.js
If your package.json file also has a module field, ES-module-aware tools like ... rollup.config.js // can be an array (for multiple inputs) export...
Read more >Package exports
The exports field in the package.json of a package allows to declare which module ... Note: Only the first valid result will be...
Read more >📔 Module Resolution
~/foo resolves foo relative to nearest node_modules directory, the nearest directory with package.json or the project root - whichever comes first.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It seems
--experimental-specifier-resolution=node
is planed to be removed in future. It might be better to think of supporting custom loaders rather than this flag specifically.IMHO relying on a flag / custom loader is not good for packages.
some issue.
nextjs remix wepack(cra, umi) resolve success.
only vite throw err