Skip to content

fix(desktop): app não abre no macOS (MAIN_VITE_NATIVEPHP_BUILD_PATH ausente) - #13

Merged
vitormattos merged 1 commit into
LibreCodeCoop:mainfrom
lfals:fix/macos-missing-vite-env
Nov 17, 2026
Merged

vitormattos merged 1 commit into
LibreCodeCoop:mainfrom
lfals:fix/macos-missing-vite-env

Conversation

@lfals

@lfals lfals commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Objetivo

Corrigir a falha de inicialização do app empacotado no macOS (v0.4.0): TypeError [ERR_INVALID_ARG_TYPE]: The "paths[1]" argument must be of type string. Received undefined.

Fixes #12

Causa

  • nativephp/electron/src/main/index.js resolve o build com path.resolve(import.meta.dirname, import.meta.env.MAIN_VITE_NATIVEPHP_BUILD_PATH).
  • Esse valor vem de nativephp/electron/.env.production (fornecido pelo NativePHP), que nunca foi versionado: o .gitignore da raiz ignora .env.*, e o arquivo se perdeu na mudança de layout (f948128).
  • Sem ele, o Vite embute undefined no build e o app fecha ao abrir, sem criar janela. O código é o mesmo em todas as plataformas.

Mudanças

  • electron.vite.config.mjs passa a definir import.meta.env.MAIN_VITE_NATIVEPHP_BUILD_PATH via define: '../../../build' em produção (igual ao .env.production do NativePHP) e NATIVEPHP_BUILD_PATH em desenvolvimento.
  • Não usa arquivos .env.* (ignorados pelo git e rejeitados por scripts/check-publication.php); nenhuma alteração em CI ou no .gitignore.
  • build/vite-env.test.mjs roda electron-vite build e falha se o bundle embutir undefined. Ainda não está ligado a nenhum workflow.

Verificações

  • node --test nativephp/electron/build/vite-env.test.mjs: aprovado, sem nenhum .env.* no disco.
  • php scripts/check-publication.php: PUBLICATION_CHECK_OK.
  • Build local native:build mac arm64 (sem assinatura) concluído; o bundle embute "../../../build" e o app empacotado abriu e permaneceu em execução, sem o erro paths[1].
  • Não verificado: abertura dos instaladores de Windows e Linux (o código é compartilhado, mas não foram testados).

Limites

  • O v0.4.0 já publicado continua com o valor embutido como undefined; é necessário um novo release.
  • O bloqueio inicial do Gatekeeper (app sem assinatura/notarização válida) é um problema separado, fora do escopo deste PR.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T16:56:52.961635Z b9e4b8d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b6e7cef71

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread nativephp/electron/.env.production Outdated
@@ -0,0 +1 @@
MAIN_VITE_NATIVEPHP_BUILD_PATH='../../../build'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Exempt the Vite environment files from the publication gate

On a clean checkout of this commit, php scripts/check-publication.php exits 1 because scripts/check-publication.php:44–47 exempts only .env.example and rejects both newly tracked Vite environment files as private_or_python_file. This check runs in .github/workflows/php-ci.yml:41–42 and .github/workflows/desktop-release.yml:97–102, so PHP verification fails and every installer job is blocked before packaging. Add narrowly scoped exceptions for these two non-secret build configuration files to the publication checker, not just .gitignore, while retaining the restrictions on other environment files.

Useful? React with 👍 / 👎.

@lfals
lfals force-pushed the fix/macos-missing-vite-env branch from 9108fb8 to bb010e6 Compare November 17, 2026 16:38

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb010e64e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// If Vite inlines `undefined`, the packaged app crashes on launch (ERR_INVALID_ARG_TYPE).
test('production main bundle embeds a defined build path', () => {
const root = fileURLToPath(new URL('..', import.meta.url));
execFileSync('npx', ['electron-vite', 'build'], { cwd: root, stdio: 'pipe' });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use a Windows-compatible executable to launch the build test

On a standard Windows Node/npm installation, npx is provided through a npx.cmd shim, which execFileSync cannot execute without a command shell. This makes the new regression test fail before Electron Vite runs, even when all build dependencies are installed. Invoke Electron Vite's local JavaScript CLI with process.execPath, or explicitly handle Windows shell execution, so the test can run on all supported desktop platforms.

Useful? React with 👍 / 👎.

@lfals
lfals force-pushed the fix/macos-missing-vite-env branch from bb010e6 to 8489b7e Compare November 17, 2026 16:47
The main bundle reads MAIN_VITE_NATIVEPHP_BUILD_PATH from nativephp/electron/.env.production,
which was never committed because the root .gitignore ignores .env.*. Vite then
inlined undefined and path.resolve crashed the packaged app on launch
(ERR_INVALID_ARG_TYPE).

Define the value in electron.vite.config.mjs instead and add a test that builds
the bundle and fails if the path is undefined.

Fixes LibreCodeCoop#12

Signed-off-by: Luis Amorim <principal@felps.zip>
@lfals
lfals force-pushed the fix/macos-missing-vite-env branch from 8489b7e to b9e4b8d Compare November 17, 2026 16:53
@vitormattos
vitormattos merged commit fdf8971 into LibreCodeCoop:main Nov 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App não abre no macOS (v0.4.0)

2 participants