Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous writing in defineConfig will cause npm run build to fail. #16572

Closed
7 tasks done
zyronon opened this issue May 1, 2024 · 3 comments
Closed
7 tasks done
Labels
invalid This doesn't seem right

Comments

@zyronon
Copy link

zyronon commented May 1, 2024

Describe the bug

Writing asynchronously in defineConfig will cause npm run build to fail when Github Action executes the job of docker/build-push-action@v5, but local packaging is completely normal.

image

Reproduction

https://github.com/zyronon/docker-test

Steps to reproduce

Https://github.com/zyronon/docker-test/, which is a new project just created with pnpm create vite, in which only the vite.config.ts file is modified

It is found that this method of writing is normal for local packaging, but it will fail in Github Action and do not report an error.

import {defineConfig} from 'vite'
import Vue from '@vitejs/plugin-vue'
import {getLastCommit} from 'git-last-commit'

export default defineConfig(async () => {
  const latestCommitHash = await new Promise<string>((resolve) => {
    return getLastCommit((err, commit) => (err ? 'unknown' : resolve(commit.shortHash)))
  })
  return {
    plugins: [
      Vue()
    ],
    define: {
      LATEST_COMMIT_HASH: JSON.stringify(
        latestCommitHash + (process.env.NODE_ENV === 'production' ? '' : ' (dev)')
      )
    },
  }
})

However, there is no problem with this writing either locally or in Github Action.

import {defineConfig} from 'vite'
import Vue from '@vitejs/plugin-vue'
import {getLastCommit} from 'git-last-commit'

export default defineConfig(() => {
  return new Promise(resolve => {
    let latestCommitHash = ''
    getLastCommit((err, commit) => {
      if (!err) latestCommitHash = commit.shortHash
      resolve({
        plugins: [
          Vue()
        ],
        define: {
          LATEST_COMMIT_HASH: JSON.stringify(
            latestCommitHash + (process.env.NODE_ENV === 'production' ? '' : ' (dev)')
          )
        },
      })
    })
  })
})

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 AMD Ryzen 5 5600G with Radeon Graphics
    Memory: 16.16 GB / 27.90 GB
  Binaries:
    Node: 18.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.19.3 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.15.4 - C:\Program Files\nodejs\pnpm.CMD
    bun: 1.1.4 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (123.0.2420.97)
    Internet Explorer: 11.0.19041.3636

Used Package Manager

pnpm

Logs

No response

Validations

@sapphi-red
Copy link
Member

You are not calling resolve or reject when !!err is true. Not calling either of them causes Node.js to exit the process without any messages (nodejs/promises-debugging#16).

const latestCommitHash = await new Promise<string>((resolve) => {
  return getLastCommit((err, commit) => (err ? 'unknown' : resolve(commit.shortHash)))
})

Closing as this is not a bug in Vite.

@sapphi-red sapphi-red added invalid This doesn't seem right and removed pending triage labels May 2, 2024
@zyronon
Copy link
Author

zyronon commented May 2, 2024

You are not calling resolve or reject when !!err is true. Not calling either of them causes Node.js to exit the process without any messages (nodejs/promises-debugging#16).

const latestCommitHash = await new Promise<string>((resolve) => {
  return getLastCommit((err, commit) => (err ? 'unknown' : resolve(commit.shortHash)))
})

Closing as this is not a bug in Vite.

But locally, everything is okay, why?

@sapphi-red
Copy link
Member

I guess it's because getLastCommit doesn't error on local and errors on GitHub Actions.

@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants