axios:1.6.2 - SyntaxError: Cannot use import statement outside a module
Describe the bug
SyntaxError: Cannot use import statement outside a module
To Reproduce
- install [email protected]
- Run Jest
Code snippet
No response
Expected behavior
No response
Axios Version
1.6.2
Adapter Version
No response
Browser
No response
Browser Version
No response
Node.js Version
18.19.0
OS
No response
Additional Library Versions
React 18.2
Additional context/Screenshots
No response
I hit this as well, after updating to 1.6.2. Not sure what the 'right' fix is, but I fixed it by adding the following to my jest config:
moduleNameMapper: {
axios: 'axios/dist/node/axios.cjs'
},
axios: 'axios/dist/node/axios.cjs'
This works.
Btw a more apt fix would be
moduleNameMapper: {
'^axios$': 'axios/dist/node/axios.cjs'
},
so that no other module like "gaxios" from googleapis, or any other similar thing gets overwritten.
Is there any new msg? The issues in version 1.9.0 still exist.
\node_modules.pnpm\[email protected]\node_modules\axios\lib\helpers\cookies.js:1 (function (exports, require, module, __filename, __dirname) { import utils from './../utils.js'; ^^^^^^
SyntaxError: Cannot use import statement outside a module
at new Script (node:vm:118:7)
at Socket.