@vue/vue3-jest: Error when using second script tag to export a variable
See original GitHub issueI have to add a second script tag because I need to export a variable for usage in storybook and jest. In storybook all is well, however Jest gives me issues. I followed the readme exactly. I’m guessing the transform doesn’t handle multiple script tags. Here’s the relevant info.
.vue file
<script>
export const storeMod = 'myVuexModuleNamespace';
... other imports
</script>
<script setup>
...
</script>
jest.config.js
transform: {
'^.+\\.vue$': '@vue/vue3-jest',
},
Error message in Jest
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/Users/... my file
^
SyntaxError: Identifier 'storeMod' has already been declared
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:5
Top Results From Across the Web
Can I access variables from another file? - javascript
As Fermin said, a variable in the global scope should be accessible to all scripts loaded after it is declared. You could also...
Read more >GDScript exports - Godot Docs
In Godot, class members can be exported. This means their value gets saved along with the resource (such as the scene) they're attached...
Read more >Understanding Shell Script Variables
Variables - Part 1 - A Bourne Shell Programming / Scripting Tutorial for learning about using the Unix shell.
Read more >How to access variables from another file using JavaScript
In JavaScript, variables can be accessed from another file using the <script> tags or the import or export statement. The script tag is ......
Read more >JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax. A background on modules. JavaScript programs started off pretty ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any updates on this? I’m having the same issue here, but I’m using
vue 2.7
, I’m using a second script tag to addname
property to a component.On our side, we switched from jest to vitest