tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
82.64k stars 2.48k forks source link

[bug] nextjs build standalone support plz #10204

Closed 01026551290 closed 3 months ago

01026551290 commented 3 months ago

Describe the bug

hi I'm basically doing a standalone build on nextjs, so when building .next/standalone is supposed to fall off. But I have a question here. When I run it on dev, the screen is coming out well, but I can't find the screen when building. What's the reason?

{
  "$schema": "../node_modules/@tauri-apps/cli/schema.json",
  "build": {
    "beforeDevCommand": "yarn dev",
    "devPath": "http://127.0.0.1:3000",
    "distDir": "../.next"
  },
  "package": {
    "productName": "new.theshop.admin",
    "version": "0.1.0"
  },
  "tauri": {
    "allowlist": {
      "all": false
    },
    "bundle": {
      "active": true,
      "category": "DeveloperTool",
      "copyright": "",
      "deb": {
        "depends": []
      },
      "externalBin": [],
      "icon": [
        "icons/32x32.png",
        "icons/128x128.png",
        "icons/128x128@2x.png",
        "icons/icon.icns",
        "icons/icon.ico"
      ],
      "identifier": "com.tauri.admin",
      "longDescription": "",
      "macOS": {
        "entitlements": null,
        "exceptionDomain": "",
        "frameworks": [],
        "providerShortName": null,
        "signingIdentity": null
      },
      "resources": [],
      "shortDescription": "",
      "targets": "all",
      "windows": {
        "certificateThumbprint": null,
        "digestAlgorithm": "sha256",
        "timestampUrl": ""
      }
    },
    "security": {
      "csp": null
    },
    "updater": {
      "active": false
    },
    "windows": [
      {
        "fullscreen": false,
        "height": 600,
        "resizable": true,
        "title": "new.theshop.admin",
        "width": 800
      }
    ]
  }
}

const { i18n } = require('./next-i18next.config');

const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
});

/** @type {import('next').NextConfig} */
const nextConfig = {
  basePath: process.env.NEXT_PUBLIC_BASE_PATH,
  reactStrictMode: true,
  output: 'standalone',
  images: {
    domains: process.env.NEXT_PUBLIC_IMG_DOMAIN.split(',') || [],
    unoptimized: true,
  },
  i18n,
  webpack(config) {
    config.module.rules.push({
      test: /\.svg$/,
      use: ['@svgr/webpack'],
    });

    return config;
  },
  compiler: {
    removeConsole:
      process.env.REMOVE_CONSOLE === 'TRUE'
        ? {
            exclude: ['error'],
          }
        : false,
  },
  transpilePackages: ['lodash-es'],
  modularizeImports: {
    'lodash-es': {
      transform: 'lodash-es/{{member}}',
      preventFullImport: true,
    },
  },
  eslint: {
    ignoreDuringBuilds: true,
  },
  typescript: {
    ignoreBuildErrors: true,
  },
};

module.exports = withBundleAnalyzer(nextConfig);

Reproduction

No response

Expected behavior

No response

Full tauri info output

[✔] Environment
    - OS: Mac OS 14.5.0 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.79.0 (129f3b996 2024-06-10)
    ✔ cargo: 1.79.0 (ffa9cf99a 2024-06-03)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 20.8.0
    - pnpm: 8.9.2
    - yarn: 1.22.19
    - npm: 10.1.0

[-] Packages
    - tauri [RUST]: 1.7.1
    - tauri-build [RUST]: 1.5.3
    - wry [RUST]: 0.24.10
    - tao [RUST]: 0.16.9
    - @tauri-apps/api [NPM]: 1.6.0
    - @tauri-apps/cli [NPM]: 1.6.0

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../.next
    - devPath: http://127.0.0.1:3000/
    - framework: React (Next.js)
    - bundler: Webpack

Stack trace

No response

Additional context

No response

FabianLars commented 3 months ago

Tauri does not have a nodejs nor nextjs runtime in build mode but you still need one in standalone mode to run your nextjs app. The only difference between standalone and standard is that standalone inlines the node_modules dependency into the standalone bundle so that you don't have to install them on your server.

This is why we're always talking about output: export in our docs. This will generate a (prerendered) static output that any standard http server can serve without a nodejs runtime.

If you need a running nodejs runtime, because you use features that are incompatible with output: export you could sidecar your frontend instead, which of course will increase the bundle size and is not as straight forward (we don't have a guide for that, so you're a bit on your own)

01026551290 commented 3 months ago

Nextjs is moving the project based on the server, do you have any plans to support the server based project?

FabianLars commented 3 months ago

Not in the near future, no (i assume at some point we will). The whole idea of Tauri was to get rid of the nodejs runtime in webbased desktop apps.