I am able to run my NextJS/Tauri app using
npm run tauri dev
This works fine, I can develop and build my app, everything works as expected.
What I am having trouble with now is trying to export this app to .exe / .msi etc or “build”.
When I run
npm run tauri build
I get a wide array of issues I have been slowly trying to work through.
- I first struggled to produce a build at all due to client side access to elements such as “Window”, I have fixed these issues.
- The next issue I have is “ReferenceError: navigator is not defined”
Export encountered errors on following paths:
/page: /
Error beforeBuildCommand `next build` failed with exit code 1
I have been able to get around this issue by adding the following pageExtensions content to my next.config.mjs . If I add this content though, then my dev environment stops working, so I have to take this back out to continue development (not ideal).
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
images: {
unoptimized: true,
},
pageExtensions: [
"icons.tsx",
"icons.ts"
]
};
- Next I have been able to build .exe / .msi successfully, however once installed and launched, I get the issue where the application cannot connect to localhost. I have seen some things online that this may be to do with the NextJS static exports, and that the destDir should have an index.html file in it, however my output directory never produces such a file.
I find my self to now be a little bit stumped on how to proceed. I can either have a working dev environment, or a non working build, but not both.
Please find below some additional information to assist.
Part of tauri.conf.json
"build": {
"beforeBuildCommand": "next build",
"beforeDevCommand": "npm run dev",
"devPath": "http://localhost:3000",
"distDir": "../out"
},
Versions:
Tauri: 1.6.0
NextJS: 14.2.10
NPM: 10.8.1
Node: 20.16.0
I have tried so many different things from so many different posts, including following all the Static file contents on NextJS, all the Tauri nextjs help doco, and numerous stack overflow posts and github issue threads, no success yet.
Any assistance is appreciated.
1