Vite, Vue3, Jest, Pinia - SyntaxError: Cannot use import statement outside a module #1406
Replies: 3 comments
-
It seems like jest isn't importing the right pinia dist file (pinia.esm-browser is for native module browser usage). It should be either using the cjs or the mjs version You also seem to not be transpiling pinia in your transformIgnorePatterns. You could remove the rule for pinia to transpile import statements. |
Beta Was this translation helpful? Give feedback.
-
Did the suggested answer work for you @drseu55? Doesn't seem like it solved the issue for me, I also tried adding a
|
Beta Was this translation helpful? Give feedback.
-
I ran into this same issue when upgrading from jest 27 to 28. It seems that {
"testEnvironment": "jsdom",
"testEnvironmentOptions": {
"customExportConditions": ["node", "node-addons"]
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Reproduction
I'm trying to use Pinia along Jest, but I'm getting the error from the title.
Steps to reproduce the bug
npm init vue@latest
npm install --save-dev jest @vue/vue3-jest @vue/test-utils@next babel-core@bridge @babel/preset-env @babel/plugin-transform-runtime jest-environment-jsdom ts-jest
Expected behavior
Being able to use Pinia with Jest.
Actual behavior
My test file looks like this.
I am trying to execute the test file with
jest src
command, but I am getting this error:My configuration for Babel and Jest file looks like this:
My package versions:
Additional information
No response
Beta Was this translation helpful? Give feedback.
All reactions