Skip to content

vue + jest + typescript: Unexpected token import #134

@mattgrande

Description

@mattgrande

Hi all, I have a Typescript file which imports a Vue file. It seems vue-jest doesn't like this?

/path-to-my-project/Autocomplete/Autocomplete.vue:14
import ItemTemplate from './_autocomplete_item.vue';
^^^^^^

SyntaxError: Unexpected token import

> 1 | import Autocomplete from './Autocomplete/Autocomplete.vue';
    | ^

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
  at Object.<anonymous> (path-to-my-project/base.ts:1:1)

You'll note that it's able to find Autocomplete.vue, but is unable to parse the import within Autocomplete.vue.

Here is my jest config; Am I doing something obviously wrong here?

  "jest": {
    "transform": {
      "^.+\\.tsx?$": "ts-jest",
      "^.+\\.vue$": "vue-jest"
    },
    "testRegex": "(\\./test/javascript/.*|\\.(test|spec))\\.(jsx?|tsx?)$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "vue",
      "js",
      "jsx",
      "json",
      "node"
    ]
  }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions