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:
- The package is loaded via
require('axios')
- Node.js resolves to the
main entry point: index.js
- The
index.js file uses ES Module syntax: import axios from './lib/axios.js'
- 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:
- Revert the
main field to "./dist/node/axios.cjs" (as in 1.13.5)
- Release this as a major version bump (2.0.0) since it's a breaking change
- 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.
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.jsonconfiguration 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
mainentry point configuration between versions:axios 1.13.5 (Working):
mainfield:"./dist/node/axios.cjs"(CommonJS compatible)typefield:"module"axios 1.13.6 (Broken):
mainfield:"./index.js"(ES Module format)typefield:"module"Impact
When axios 1.13.6 is used as a dependency in a CommonJS project:
require('axios')mainentry point:index.jsindex.jsfile uses ES Module syntax:import axios from './lib/axios.js'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
mainfield 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:
mainfield to"./dist/node/axios.cjs"(as in 1.13.5)./index.jsbut ensure it exports a CommonJS-compatible format when loaded viarequire()Environment
Workaround
Lock axios to version 1.13.5 using package manager overrides/resolutions.