Skip to content

Commit

Permalink
fix: main field in package.json should correspond to cjs artifacts
Browse files Browse the repository at this point in the history
When axios#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".
  • Loading branch information
thebanjomatic committed Jun 29, 2023
1 parent 21a5ad3 commit 476eac0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -2,7 +2,7 @@
"name": "axios",
"version": "1.4.0",
"description": "Promise based HTTP client for the browser and node.js",
"main": "index.js",
"main": "./dist/node/axios.cjs",
"exports": {
".": {
"types": {
Expand Down Expand Up @@ -212,4 +212,4 @@
"@commitlint/config-conventional"
]
}
}
}

0 comments on commit 476eac0

Please sign in to comment.