首页 > 解决方案 > CircleCI 无法评估 TypeScript

问题描述

我有一个前端和后端都是打字稿的项目。所有测试都在本地通过,但是,当推送到 github 上的分支时,它总是在 TypeScript 的第一个迹象时失败(在后端,现在我只专注于后端测试)。

SyntaxError: /home/circleci/project/server/src/User-Server/server.ts: Unexpected token (16:35)
  14 | app.use(apiRoutes);
  15 | 
> 16 | module.exports = app.listen(PORT, (): void => {
     |                                    ^
  17 |   console.log(` Server listening on port ${PORT} - ${ENV} environment`);
  18 | });
  19 | 

这是我的 config.yml:

version: 2
jobs: 
  build:
    docker:
      - image: circleci/node:10.15.3

    # working_directory: ~/repo
    steps:
      - checkout
      #download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-
      - run: npm install
      - run: npm test

我也将此发布到CircleCI 讨论论坛

我的 tsconfig.json

{
  "compilerOptions": {
    "module": "esnext",
    "target": "es5",
    "noImplicitAny": true,
    "preserveConstEnums": true,
    "outDir": "./dist",
    "sourceMap": true,
    "esModuleInterop": true,
    "baseUrl": "../",
    "moduleResolution": "node"
  },
  "include": ["./src/**/*"],
  "exclude": ["test", "**/*/spec.ts", "**/*/test.ts"]
}

我的 jest.config.js

module.exports = {
  preset: 'ts-jest',
  roots: ['src'],
  testEnvironment: 'node',
  transform: {
    '^.+\\.tsx?$': 'ts-jest',
  },
};

标签: typescriptjestjscircleci

解决方案


推荐阅读