axios: Latest release of axios throws SyntaxError: Unexpected identifier

Describe the bug

Started getting the following error yesterday.

/usr/src/app/node_modules/axios/index.js:1
import axios from './lib/axios.js';
       ^^^^^

SyntaxError: Unexpected identifier
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/usr/src/app/api/vendors/snd/SNDClient.js:1:15)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

Axios version in package.json was : >=0.23.0.

The issue went away when I switched to version 1.0.0-alpha.1.

I verified that I was using require to import axios in my code instead of import.

To Reproduce

Use latest version of axios in package.json

  "axios": "1.0.0",

Expected behavior

In an ideal world, the nodejs app would have started without error.

Environment

  • Axios Version 1.0.0
  • Node.js Version 12.0.0
  • OS: Debian GNU/Linux 9 (stretch) (EKS)
  • Additional Library Versions: restify: 8.6.1

Additional context/Screenshots

N/A

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 19 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I solved the error. I used an older version - npm i axios@0.21

npm i axios@1.2.0-alpha.1 didn’t work for me npm i axios@0.21 did work for me

same here, 1.3.2 doesn’t work. switching to 0.27.2 resolved the issue

I solved the error. I used an older version - npm i axios@0.21

Thanks it really worked

Still confirming same issue with 1.3.4.

Happening on v18.10.0 also

In an ideal world, the nodejs app would have started without error. Node.js Version 12.0.0

In an ideal world, people wouldn’t use legacy Node without ESM module support enabled by default 😃 Please, update your Node to v13.2.0 or later, or you can try to pass --experimental-modules cmd line argument to enable its experimental support.

I solved the error. I used an older version - npm i axios@0.21

worked here, thank you