網站搜尋

node.js - SyntaxError: 無法在 vuejs jest typescript 中的模組外使用 import 語句


我在使用 VueJs + Jest + Typescript 的 Jest 測試案例中遇到這個問題

當我跑步時

vue-cli-service test:unit

我在轉譯我的 ts 測試時遇到以下錯誤,測試因此失敗,出現如下錯誤。

語法錯誤:無法在模組外使用 import 語句

  30 |   inject
  31 | } from "@vue/composition-api";
> 32 | import { stopWatchingProperties } from "@mymods/modui-framework";
     | ^
  33 | import { reactive } from "@vue/composition-api";
  34 | 
  35 | export default {

  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
  at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
  at src/App.vue:32:1
  at Object.<anonymous> (src/App.vue:66:3)

我的 jest.config

moduleFileExtensions: [
        "js",
        "jsx",
        "json",
        "vue",
        "ts",
        "tsx"
    ],
    coveragePathIgnorePatterns: [
        "/node_modules/"
    ],
    transformIgnorePatterns: [
    ],
    transform: {
        "^.+\\.vue$": "vue-jest",
        ".+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$": "jest-transform-stub",
        "^.+\\.(tsx|ts)?$": "ts-jest"
       //"^.+\\.tsx?$": "babel-jest"
    },
    moduleNameMapper: {
        "^@/(.*)$": "<rootDir>/src/$1"
    },

我的 babel.config

module.exports = {
  presets: ["@babel/preset-env"]
};

Package.json

dependencies": {
    "@mymods/modui-framework": "0.0.6",

有什麼想法嗎,modui-framework 是我的依賴項,並且從另一個項目加載到 node-modules,而那個項目又依賴於另一個項目。

有什麼建議或想法嗎?