tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] `tauri dev` Incompatible with Next.js 13

Open jjorissen52 opened this issue 2 years ago • 2 comments

Describe the bug

Using Next.js 13 will cause a white screen and console error with tauri dev: SyntaxError: Unexpected token '.' image

Reproduction

Using any package manager, initialize a next.js app:

  • pnpm create tauri-app
  • select pnpm, next-ts
  • cd tauri-app
  • pnpm install
  • pnpm tauri dev

Expected behavior

The dev window to render the default application screen

Platform and versions

Environment › OS: Mac OS 10.14.6 X64 › Node.js: 18.13.0 › npm: 9.4.0 › pnpm: 7.26.2 › yarn: Not installed! › rustup: 1.25.1 › rustc: 1.67.0 › cargo: 1.67.0 › Rust toolchain: stable-x86_64-apple-darwin

Packages › @tauri-apps/cli [NPM]: 1.2.3 › @tauri-apps/api [NPM]: 1.2.0 › tauri [RUST]: 1.2.4, › tauri-build [RUST]: 1.2.1, › tao [RUST]: 0.15.8, › wry [RUST]: 0.23.4,

App › build-type: bundle › CSP: unset › distDir: ../dist › devPath: http://localhost:1420/ › framework: React (Next.js) › bundler: Webpack

App directory structure ├─ node_modules ├─ .next ├─ src-tauri ├─ .vscode └─ src

Stack trace

N/A

Additional context

After a clean install, you can get dev mode working by taking the following steps:

  • rm -rf node_modules/ pnpm-lock.yaml
  • change next dependency in package.json to "next": "^12"
  • pnpm install
  • pnpm tauri dev

jjorissen52 avatar Jan 29 '23 21:01 jjorissen52

So my guess is that they raised they minimum supported Safari version in next@13, at least in dev?

The webview in macos 10.14.6 should be equivalent to Safari 13.0 (but since we couldn't confirm that on an actual device it might still be 12)

FabianLars avatar Jan 30 '23 09:01 FabianLars

@FabianLars Anything you'd like me to do to gather more info?

jjorissen52 avatar Jan 30 '23 16:01 jjorissen52

Next 13 dev server works fine in my browser.

jjorissen52 avatar Jan 31 '23 00:01 jjorissen52

Next 13 dev server works fine in my browser.

That doesn't tell us much since your browser is likely not Safari v12.

Anything you'd like me to do to gather more info?

Maybe the output of navigator.userAgent from inside the tauri window. Also try building your frontend, maybe nextjs uses different targets for dev and build.

FabianLars avatar Jan 31 '23 14:01 FabianLars

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko)

I can confirm that it works as expected with tauri build.

jjorissen52 avatar Feb 01 '23 01:02 jjorissen52

@JonasKruckenberg Do you think our webview version table is inaccurate, or the user agent? because 605 is macos 10.13 (safari 11) in our table, not 10.13 🤔

FabianLars avatar Feb 01 '23 09:02 FabianLars

A js file was being tampered with in development mode as html, but it was working fine in release mode.

I found the cause of the problem, it is a cache problem, clear the tauri browser cache can be. So my problem and upstairs may not be the same.

macOS: ~/Library/Caches/com.lencx.chatgpt

Dev: Screenshot 2023-02-01 at 18 18 40

Release: Screenshot 2023-02-01 at 18 18 55

lencx avatar Feb 01 '23 10:02 lencx

Describe the bug

Using Next.js 13 will cause a white screen and console error with tauri dev: SyntaxError: Unexpected token '.' image

Reproduction

Using any package manager, initialize a next.js app:

* pnpm create tauri-app

* select pnpm, next-ts

* cd tauri-app

* pnpm install

* pnpm tauri dev

Expected behavior

The dev window to render the default application screen

Platform and versions

Environment › OS: Mac OS 10.14.6 X64 › Node.js: 18.13.0 › npm: 9.4.0 › pnpm: 7.26.2 › yarn: Not installed! › rustup: 1.25.1 › rustc: 1.67.0 › cargo: 1.67.0 › Rust toolchain: stable-x86_64-apple-darwin

Packages › @tauri-apps/cli [NPM]: 1.2.3 › @tauri-apps/api [NPM]: 1.2.0 › tauri [RUST]: 1.2.4, › tauri-build [RUST]: 1.2.1, › tao [RUST]: 0.15.8, › wry [RUST]: 0.23.4,

App › build-type: bundle › CSP: unset › distDir: ../dist › devPath: http://localhost:1420/ › framework: React (Next.js) › bundler: Webpack

App directory structure ├─ node_modules ├─ .next ├─ src-tauri ├─ .vscode └─ src

Stack trace

N/A

Additional context

After a clean install, you can get dev mode working by taking the following steps:

* rm -rf node_modules/ pnpm-lock.yaml

* change next dependency in package.json to "next": "^12"

* pnpm install

* pnpm tauri dev

Until nextjs adds support for SSG (next export) to the app dir feature it won't really work in tauri at all because there is no nodejs runtime in a tauri app , we need next export.

imagen

LucasZNK avatar Feb 25 '23 22:02 LucasZNK

Looks like support for next export with appDir was just added to Next.js 🎉

https://github.com/vercel/next.js/issues/45507#issuecomment-1473701983

airstrike avatar Mar 20 '23 15:03 airstrike

appdir is used in this repo, you can check: https://github.com/agmmnn/tauri-ui-boilerplate

agmmnn avatar Apr 12 '23 09:04 agmmnn

Closing this since it is not really an issue with tauri.

amrbashir avatar Apr 13 '23 14:04 amrbashir

@jjorissen52 I have come across the problem on macOS 10.14.6. The fix that works for me is to add tauri api package to transpiled packages list:

const nextConfig = { ... transpilePackages: ['@tauri-apps/api'], ... }

dkobylarz avatar Sep 06 '23 13:09 dkobylarz