-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Closed
Closed
Copy link
Labels
Description
Describe the bug
I have a library that defines:
{
"name": "lib",
"main": "./node.js",
"module": "./node.mjs",
"browser": "./browser.mjs",
"exports": {
"browser": "./browser.mjs",
"import": "./node.mjs",
"require": "./node.js"
}
}Contrary to the docs and expected behavior. Vite picks "module": "./node.mjs" and I get Node ESM printed. According to the docs, and Node.JS behavior, exports should be preferred and used when specified (P.S. Vite AFAIK doesn't use the browser main field).
Reproduction
https://stackblitz.com/edit/vitejs-vite-sh5wuy?file=lib/package.json
System Info
System:
OS: macOS 12.5.1
CPU: (10) arm64 Apple M1 Pro
Memory: 135.59 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v16.17.0/bin/yarn
npm: 8.19.1 - ~/.nvm/versions/node/v16.17.0/bin/npm
Browsers:
Chrome: 105.0.5195.102
Safari: 15.6.1Used Package Manager
pnpm
Logs
Click to expand!
Node ESMIt should be Browser ESM.
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 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.
Reactions are currently unavailable