-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
When trying to create a browser bundle which depends on axios@0.30.0
the following error is returned:
✘ [ERROR] Could not resolve "./node/"
node_modules/axios/lib/platform/index.js:3:25:
3 │ module.exports = require('./node/');
Steps to reproduce with axios
and esbuild
npm init -y
npm install axios@0.30.0
- Create a file
main.mjs
with the following content:
import axios from "axios";
axios.get('https://exaple.com')
.then(() => console.log('ok'));
- Run
npx esbuild --bundle --platform=browser main.mjs
Steps to reproduce with just esbuild
See the speculation section below, I think I've found the issue and created a fairly minimal reproduction of how axios triggers the issue in the "Try in the browser" tool.
Speculation
This seems to be caused by axios it's package.json containing this entry:
{
"browser": {
"./lib/platform/node/index.js": "./lib/platform/browser/index.js"
},
}
And by the axios file lib/platform/index.js
containing a reference to ./node/
, with a trailing slash:
'use strict';
module.exports = require('./node/');
- There is no error if the trailing slash is removed:
require('./node')
- There is no error if the file is referenced directly:
require('./node/index.js')
- There is no error if the bundle is targeting node:
npx esbuild --bundle --platform=node main.mjs
Conclusion
I belief esbuild is currently not correctly handling the resolution of folder references with a trailing slash when there is a matching mainFile entry for the index file or the targeted folder in the package.json?
This seems to be breaking the bundling of the axios 0.30.0 (the latest 0.x.x release) for browsers.
Thanks for looking into this 🙏