Cypress在CI Syntaxerror中没有运行:出乎意料的令牌' Export'使用Cypress-io/github-action@v2打字稿

发布于 2025-01-30 14:28:14 字数 2177 浏览 4 评论 0原文

我有以下柏树的插件文件: frontend/cypress/plugins/index.ts

export default ((on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
}) as Cypress.PluginConfig

当我在计算机上运行它时,它正在工作,但是当我在github操作中使用cypress-io/github-action@v2时我会收到以下错误:

Your pluginsFile is invalid: /home/runner/work/XX/XX/frontend/cypress/plugins/index.ts

It threw an error when required, check the stack trace below:

/home/runner/work/XX/XX/frontend/cypress/plugins/index.ts:14
export default ((on, config) => {
^^^^^^
SyntaxError: Unexpected token 'export'

这是我的.github/workflows/cypress-tests.yml

name: Cypress Tests

jobs:
  cypress-run:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
    
      - name: Install dependencies
        run: | 
          cd frontend  
          npm ci
                
      - name: Cypress run
        uses: cypress-io/github-action@v2
        with:
          working-directory: frontend
          start: npm run serve
          wait-on: 'http://localhost:8080'  

我的front> frontend/cypress.json.json配置文件是空的。 这是我的frontend/cypress/tsconfig.json在柏树文件夹中:

{
    "include": [
        "./integration/**/*",
        "./support/**/*"
    ],
    "compilerOptions": {
        "isolatedModules": false,
        "target": "es5",
        "lib": [
            "es5",
            "dom"
        ],
        "types": [
            "cypress"
        ]
    }
}

this frontend/cypress/plugins/tsconfig.json在插件文件夹中:

{
    "include": [
        "./**/*"
    ],
    "compilerOptions": {
        "module": "CommonJS",
        "preserveValueImports": false,
        "types": [
            "node",
            "cypress/types/cypress"
        ]
    }
}

我已经复制了此配置来自npm init vue@最新带有打字稿和柏树。

有什么问题?

I have the following plugin file for cypress:
frontend/cypress/plugins/index.ts:

export default ((on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
}) as Cypress.PluginConfig

When I run it on my machine it's working but when I use cypress-io/github-action@v2 in my github actions I get the following error:

Your pluginsFile is invalid: /home/runner/work/XX/XX/frontend/cypress/plugins/index.ts

It threw an error when required, check the stack trace below:

/home/runner/work/XX/XX/frontend/cypress/plugins/index.ts:14
export default ((on, config) => {
^^^^^^
SyntaxError: Unexpected token 'export'

This is my .github/workflows/cypress-tests.yml:

name: Cypress Tests

jobs:
  cypress-run:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
    
      - name: Install dependencies
        run: | 
          cd frontend  
          npm ci
                
      - name: Cypress run
        uses: cypress-io/github-action@v2
        with:
          working-directory: frontend
          start: npm run serve
          wait-on: 'http://localhost:8080'  

My frontend/cypress.json config file is empty.
This is my frontend/cypress/tsconfig.json in the cypress folder:

{
    "include": [
        "./integration/**/*",
        "./support/**/*"
    ],
    "compilerOptions": {
        "isolatedModules": false,
        "target": "es5",
        "lib": [
            "es5",
            "dom"
        ],
        "types": [
            "cypress"
        ]
    }
}

This frontend/cypress/plugins/tsconfig.jsonis inside the Plugins folder:

{
    "include": [
        "./**/*"
    ],
    "compilerOptions": {
        "module": "CommonJS",
        "preserveValueImports": false,
        "types": [
            "node",
            "cypress/types/cypress"
        ]
    }
}

I have copied this configuration from npm init vue@latest with typescript and cypress.

What's the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

是伱的 2025-02-06 14:28:14

我忘了将打字稿添加到我的依赖项中:

npm install typescript --save-dev

I forgot to add typescript to my dependencies:

npm install typescript --save-dev
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文