Skip to content

axios version 1.13.6 package.json "Cannot use import statement outside a module" in node 12 #7463

@SunXinFei

Description

@SunXinFei

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions