question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@vue/vue3-jest: Error when using second script tag to export a variable

See original GitHub issue

I 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:open
  • Created 2 years ago
  • Reactions:6
  • Comments:5

github_iconTop GitHub Comments

2reactions
Adnan-kreikercommented, Nov 18, 2022

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 add name property to a component.

0reactions
jess-ikacommented, Nov 18, 2022

On our side, we switched from jest to vitest

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found