From 7373fbff24cd92ce650d99ff6f7fe08c2e2a0a04 Mon Sep 17 00:00:00 2001 From: Adam Hines Date: Tue, 30 Dec 2025 05:10:04 -0700 Subject: [PATCH] fix: main field in package.json should correspond to cjs artifacts (#5756) When https://github.com/axios/axios/pull/4787 was implemented, the project was switched to `"type": "module"` and "./index.js" became an esm file instead of commonjs, however, the "main" entry in package.json still points to "index.js". As a result, consumers using this field may get unexpected behavior since the main field is supposed to be commonjs if the entry is provided. Many consumers won't run into this as a practical problem (for example when just doing `const axios = require('axios').default` from inside of a cjs file in node) because the "exports" map takes precedence over the main/module fields, but tools that don't parse the object map when resolving still run into problems here. The fix for this is to just point the "main" entry-point to the commonjs artifacts located at "./dist/node/index.cjs". I also added a module entrypoint to improve compatability for the cases where the export map is not used (webpack 4 for example) since that would likely be reading the cjs "main" entrypoint now that main has switched back to cjs. Co-authored-by: Jay --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f0973efe..eb58f1a2 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "name": "axios", "version": "1.13.2", "description": "Promise based HTTP client for the browser and node.js", - "main": "index.js", + "main": "./dist/node/axios.cjs", + "module": "./index.js", "exports": { ".": { "types": {