-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Open
Labels
feat: library modep2-edge-caseBug, but has workaround or limited in scope (priority)Bug, but has workaround or limited in scope (priority)
Description
Describe the bug
use vite to build a lib for nodejs
The source code in axios is like below:
function getDefaultAdapter() {
var adapter;
if (typeof XMLHttpRequest !== 'undefined') {
// For browsers use XHR adapter
adapter = require('../adapters/xhr.js');
} else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
// For node use HTTP adapter
adapter = require('../adapters/http');
}
return adapter;
}
After building. The result bundle is not correct. Http adapter is resolved as xhr.
function getDefaultAdapter() {
var adapter;
if (typeof XMLHttpRequest !== "undefined") {
adapter = xhr;
} else if (typeof process !== "undefined" && Object.prototype.toString.call(process) === "[object process]") {
adapter = xhr;
}
return adapter;
}
Then i got the error: UnhandledRejection ReferenceError: XMLHttpRequest is not defined
Reproduction
https://github.com/Sara2009/vite-require
System Info
"vite": "^2.9.13",
Used Package Manager
yarn
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 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.
abdul-alhasany, seahindeniz and silverwind
Metadata
Metadata
Assignees
Labels
feat: library modep2-edge-caseBug, but has workaround or limited in scope (priority)Bug, but has workaround or limited in scope (priority)