axios version 1.13.6 package.json "Cannot use import statement outside a module" in node 12
envgap__axios__axios-7463
01 / FAILURE SIGNATURE
As reported upstream
SyntaxError: Cannot use import statement outside a module
Not a benchmark task.
- The project already builds and runs before the fix, so there is nothing to repair.
02 / ENVIRONMENT RECIPE
- Base commit
d6dcbfd53e9506d9c8c0b1fd09c4d960bea9b9f0- Manifest
package.json- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / ORIGINAL ISSUE TEXT
axios/axios #7463 · read the original issue
Issue Title
axios 1.13.6 breaks CommonJS compatibility - "Cannot use import statement outside a module"
Issue Description
### Description
The axios 1.13.6 release introduces a breaking change in the `package.json` configuration that causes **"Cannot use import statement outside a module"** errors in CommonJS (Node.js) environments.
### Root Cause
The issue is caused by a change in the `main` entry point configuration between versions:
**axios 1.13.5 (Working):**
- `main` field: `"./dist/node/axios.cjs"` (CommonJS compatible)
- `type` field: `"module"`
**axios 1.13.6 (Broken):**
- `main` field: `"./index.js"` (ES Module format)
- `type` field: `"module"`
### Impact
When axios 1.13.6 is used as a dependency in a CommonJS project:
1. The package is loaded via `require('axios')`
2. Node.js resolves to the `main` entry point: `index.js`
3. The `index.js` file uses ES Module syntax: `import axios from './lib/axios.js'`
4. This causes the error: **"Cannot use import statement outside a module"**
### Reproduction
This issue occurs when axios 1.13.6 is installed as a nested dependency in a CommonJS Node.js project.
Example error stack:
SyntaxError: Cannot use import statement outside a module
/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/index.js:1
import axios from './lib/axios.js';
^^^^^^
### Expected Behavior
The `main` field should point to a CommonJS-compatible entry point (like `./dist/node/axios.cjs`) to maintain backward compatibility with CommonJS environments.
### Suggested Fix
One of the following:
1. Revert the `main` field to `"./dist/node/axios.cjs"` (as in 1.13.5)
2. Release this as a major version bump (2.0.0) since it's a breaking change
3. Keep `./index.js` but ensure it exports a CommonJS-compatible format when loaded via `require()`
### Environment
- Node.js version: 12.13.1 (CommonJS)
- npm version: 6.x
- axios version: 1.13.6
### Workaround
Lock axios to version 1.13.5 using package manager overrides/resolutions.04 / LABELS
Labels from the report text only; not yet run
No supported category has been assigned.
Label rules and the text that matched
[]