vue-signature icon indicating copy to clipboard operation
vue-signature copied to clipboard

Using Jest: Cannot use import statement outside a module

Open ricardovanlaarhoven opened this issue 3 years ago • 2 comments

Test suite failed to run

    .........\node_modules\vue-signature\src\main.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import VueSignature from './components/vueSignature.vue'
                                                                                             ^^^^^^

    SyntaxError: Cannot use import statement outside a module

When i use jest, i'm getting this errror, even when the parent component is shallow mounted. When i just serve or build this, i'm not getting this error

ricardovanlaarhoven avatar Jan 31 '22 14:01 ricardovanlaarhoven

I am getting this error with nuxt. But not right away. Only after like 2 minutes does the error come. Once it arrived it doesn't go away. Super weird.

tintin10q avatar Apr 06 '22 04:04 tintin10q

I also had this issue with Jest. May not fit your exact use case, but the solution for me was to set an exclusion to this package for the transformIgnorePatterns in my jest.config.js like so:

transformIgnorePatterns: ['/node_modules/(?!vue-signature)'],

This was recommended in the testing config docs for @vue/cli-plugin-unit-jest https://www.npmjs.com/package/@vue/cli-plugin-unit-jest

hanschun avatar Nov 08 '22 17:11 hanschun