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

[bug] CLI cannot find app_dir in a subdirectory of current working directory with some commands (inconsistent) #10417

Closed
samkearney opened this issue Jul 29, 2024 · 1 comment · Fixed by #10418
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@samkearney
Copy link
Contributor

samkearney commented Jul 29, 2024

Describe the bug

Consider the following project layout:

src-tauri/
  tauri.conf.json
  <other Tauri sources>
src-web/
  package.json
  <other web sources>

It seems like the tauri CLI is written to be flexible to different project layouts such as this one. This is based on what I see primarily in https://github.com/tauri-apps/tauri/blob/dev/tooling/cli/src/helpers/app_paths.rs; in get_app_dir() there is some logic to walk subdirectories until finding a package.json file.

However, this doesn't work for some commands like dev and build because these commands set the current directory to src-tauri before running the code that relies on get_app_dir(). Then the get_app_dir() search starts in src-tauri instead of the working directory where the command was run.

The command info does not have this issue, because it does not change the current working directory before running.

I am not sure if layouts like this one are supposed to be supported, but I think the behavior of the CLI should at least be consistent across commands. I was going to open a PR for this, but I didn't know how much stuff in the CLI relies on the stateful changing of the current working directory...

Reproduction

  1. Create a new project: npm create tauri-app@latest -- --beta (I chose: TypeScript/React/npm/no mobile)
  2. Create a new directory inside the project called src-web, move all web-related sources into this directory
  3. Run cargo tauri dev

Output:

    Running BeforeDevCommand (`npm run dev`)
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\git\iQ-Next\package.json
npm ERR! errno -4058
npm ERR! enoent Could not read package.json: Error: ENOENT: no such file or directory, open 'C:\git\tauri-test\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in: C:\Users\samuel.kearney\AppData\Local\npm-cache\_logs\2024-07-29T18_03_00_167Z-debug-0.log
    Error The "beforeDevCommand" terminated with a non-zero status code.

Expected behavior

Dev server starts successfully

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.19045 X64
    ✔ WebView2: 126.0.2592.113
    ✔ MSVC:
        - Visual Studio Professional 2019
        - Visual Studio Professional 2022
    ✔ rustc: 1.76.0 (07dca489a 2024-02-04)
    ✔ cargo: 1.76.0 (c84b36747 2024-01-18)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (environment override by RUSTUP_TOOLCHAIN)
    - node: 18.18.0
    - npm: 9.8.1

[-] Packages
    - tauri [RUST]: 2.0.0-beta.25
    - tauri-build [RUST]: 2.0.0-beta.19
    - wry [RUST]: 0.41.0
    - tao [RUST]: 0.28.1
    - tauri-cli [RUST]: 2.0.0-beta.23
    - @tauri-apps/api [NPM]: 2.0.0-beta.16
    - @tauri-apps/cli [NPM]: 2.0.0-beta.23

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: React
    - bundler: Vite

Stack trace

No response

Additional context

No response

@samkearney samkearney added status: needs triage This issue needs to triage, applied to new issues type: bug labels Jul 29, 2024
@samkearney
Copy link
Contributor Author

Update: I have added a proposed implementation in #10418.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant