【问题标题】:Not 'sourceType: module' error when testing Angular with Cypress in TypeScript在 TypeScript 中使用 Cypress 测试 Angular 时不会出现“sourceType:模块”错误
【发布时间】:2020-03-17 08:17:20
【问题描述】:

我在 Cypress 4.2.0 版的 Angular 8 项目中,尝试导入 .ts 文件时出现以下错误

/.../cypress/integration/main.spec.ts:1
import { MOCK1, MOCK2, MOCK3 } from '../fixtures/mocks/index';
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

我的tsconfig.json

{
    "compilerOptions": {
        "strict": true,
        "baseUrl": "../node_modules",
        "target": "ES6",
        "lib": ["es5", "dom"],
        "types": ["cypress"]
    },
    "include": ["**/*.ts"]
}

【问题讨论】:

    标签: angular typescript cypress


    【解决方案1】:

    看起来是必需的sourceType": "module"

    {
      "parser": "babel-eslint",
      "parserOptions": {
        "sourceType": "module",
        "allowImportExportEverywhere": true
      }
    }
    

    参考链接https://github.com/babel/babel-eslint#configuration

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-09
      • 2021-04-26
      • 2023-03-26
      • 2020-07-20
      • 2022-08-02
      • 1970-01-01
      • 2018-03-21
      • 2018-01-24
      相关资源
      最近更新 更多