I have a Vue.js application with two files containing:
From "axios"
Import axios
These files are located in src/lib within the application and contain the import statement on the first line.
Regardless of what package.json says, running the tests on Github will cause Axios 1.0.0 to be installed, and now any tests involving these files will fail with the above error.
Changing the statement toconst axios = require("axios")
also fails; node_modules/axios/index.js contains an import statement on line 1 and throws the exception there.
One suggestion I often see for issues like this is to add"type": "module"
to package.json (at the same level as src/ ). This will cause all tests to fail and require vue.config.js to be renamed to vue.config.cjs. Doing this confuses me:Error: You appear to be using the native ECMAScript module configuration file, which is only supported when running Babel asynchronously
, which I don't understand.
Can anyone suggest what to do here?
I was able to fix this error by adding a force jest import commonjs axios build
to my
package.json
. Other solutions usingtransformIgnorePatterns
didn't work for me.