Search code examples
testingimportvuejs2modulesyntax-error

Vue2 and unit tests : SyntaxError: Cannot use import statement outside a module


I am doing unit tests with vue-utils on the front-end of an application written in vue2.

When I run my test, I get this error: SyntaxError: Cannot use import statement outside a module (I don't even need the problematic module in my test.)

I have looked at several answers on the subject (including adding "type": "module" in package.json or add extension ".mjs") but I always get an additional error after testing the solution. I work with node/14.19.2.

Do you have any idea? I don't know which file to show you, don't hesitate to ask me for my code


Solution

  • I solve my issue by adding this line:

    transformIgnorePatterns: ['node_modules/(?!module_name)']
    

    in my jest.config.js file