{"id":202,"hash":"554c52b65232dc5697daf5901294e71aaf9bdf82617e95c848f7fad13cd3de36","pattern":"&quot;Cannot use import statement outside a module&quot; with Axios","full_message":"I have a Vue.js application where two files contain:\n\nimport axios from \"axios\"\n\nThese files are located in src/lib within the application and include the import statement on their first line.\n\nRunning tests on Github causes Axios 1.0.0 to be installed, no matter what the package.json says, and now any test involving these files fails with the above error.\n\nChanging the statement to const axios = require(\"axios\") fails also; node_modules/axios/index.js contains an import statement on line 1 and the exception is thrown there.\n\nA suggestion I've seen quite often for such issues is to add \"type\": \"module\" to package.json (which is at the same level as src/). This causes all tests to fail with a demand to rename vue.config.js as vue.config.cjs. Doing that gets me:  Error: You appear to be using a native ECMAScript module configuration file, which is only supported when running Babel asynchronously, which I do not understand.\n\nCan anyone suggest what to do here?","ecosystem":"npm","package_name":"node.js","package_version":null,"solution":"I was able to fix this error by forcing jest to import the commonjs axios build by adding\n\n  \"jest\": {\n    \"moduleNameMapper\": {\n      \"^axios$\": \"axios/dist/node/axios.cjs\"\n    }\n  },\n\nto my package.json.  Other solutions using transformIgnorePatterns didn't work for me.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/73958968/cannot-use-import-statement-outside-a-module-with-axios","votes":154,"created_at":"2026-04-19T04:41:31.372199+00:00","updated_at":"2026-04-19T04:51:33.558817+00:00"}