-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Description
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):
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:
- The package is loaded via
require('axios') - Node.js resolves to the
mainentry point:index.js - The
index.jsfile 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
mainfield 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.jsbut ensure it exports a CommonJS-compatible format when loaded viarequire()
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.