axios icon indicating copy to clipboard operation
axios copied to clipboard

axios:1.6.2 - SyntaxError: Cannot use import statement outside a module

Open hanoj-budime opened this issue 2 years ago • 3 comments

Describe the bug

SyntaxError: Cannot use import statement outside a module

image

To Reproduce

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

hanoj-budime avatar Dec 15 '23 06:12 hanoj-budime

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'
    },

benheymink avatar Dec 26 '23 13:12 benheymink

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.

Ashniu123 avatar Jun 24 '24 07:06 Ashniu123

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. ([eval]:18:19) at Socket.emit (node:events:518:28) at addChunk (node:internal/streams/readable:561:12) at readableAddChunkPushByteMode (node:internal/streams/readable:512:3) at Readable.push (node:internal/streams/readable:392:5) at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)

A25468451 avatar May 13 '25 03:05 A25468451