'vue3 + element-plus jest
npm run jest no problem but npm run jest --coverage
Identifier '_interopRequireDefault' has already been declared. (133:9)
131 | var _FPLogo = _interopRequireDefault(require("@/assets/logo-02.png"));
132 |
> 133 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
| ^
134 |
135 | const _hoisted_1 = {
136 | class: "login-container columnCC",
jest.config
module.exports = {
moduleFileExtensions: [
'ts',
'js',
'jsx',
'tsx',
'json',
// tell Jest to handle *.vue files
'vue'
],
// setupFiles: ['./__tests__/setup.js'],
transform: {
// process *.vue files with vue-jest
'^.+\\.vue$': require.resolve('vue-jest'),
'^.+\\.tsx?$': require.resolve('ts-jest'),
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$':
require.resolve('jest-transform-stub'),
'^.+\\.jsx?$': require.resolve('babel-jest')
},
transformIgnorePatterns: ['/node_modules/'],
// support the same @ -> src alias mapping in source code
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},
// testEnvironment: 'jest-environment-jsdom-fifteen',
// serializer for snapshots
snapshotSerializers: ['jest-serializer-vue'],
testMatch: [
'**/tests/unit/**/*.spec.[jt]s?(x)',
'**/__tests__/*.[jt]s?(x)',
'**/__tests__/**/*.spec.[jt]s?(x)',
],
// https://github.com/facebook/jest/issues/6766
testURL: 'http://localhost/'
}
.babelrc
{
"plugins": [
"babel-plugin-transform-vite-meta-env"
],
"presets": [
"@vue/babel-preset-jsx",
[
"babel-preset-vite"
],
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
If there is more than one, an error will be reported
What should I do to avoid this mistake I hope it can be compiled normallySources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
