Hi everyone!
I’m trying to install Vitest on a newly created Ionic-angular project and I’m getting into troubles. I followed this article to install Vitest :
But ng test
ends with this error:
Cannot use import statement outside a module
Module /node_modules/.pnpm/@ionic+core@7.8.4/node_modules/@ionic/core/components/ion-back-button.js:4
seems to be an ES Module but shipped in a CommonJS package.
You might want to create an issue to the package "@ionic/core" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.
As it is suggested, I have updated the vite.config.mts
file :
export default defineConfig(({ mode }) => {
return {
plugins: [angular()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['src/test-setup.ts'],
include: ['**/*.spec.ts'],
reporters: ['default'],
server: {
deps: {
inline: ["@ionic/core"]
}
}
},
define: {
'import.meta.vitest': mode !== 'production',
},
};
});
but ng test
ends with the same error.
Has anyone managed to make it work ?