Electron + NextJS 13+ with output="export"
Unanswered
Mümin Celal Pinar posted this in #help-forum
I am trying to run NextJS 13 with Electron and application is working on development but when I try to build it I am struggling with routing. Routing is not working on production.
next.config.js
scripts
UI loading without problem but on routing I am getting the error that attachted as image.
output="export" generates .txt files and on production, router.push('/login') try to call file:///login/index.txt
How can I solve this?
next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
reactStrictMode: true,
images: {
unoptimized: true
},
eslint: {
ignoreDuringBuilds: true
}
};
module.exports = nextConfig;scripts
"scripts": {
"clean": "rimraf out dist .next",
"dev:ui": "rimraf out .next && next dev -p 3000",
"dev:electron": "electron .",
"start:ui": "next start",
"lint": "eslint src/**/*.{js,jsx} --fix",
"format": "prettier --write src/**/*.{js,jsx}",
"build:ui": "next build",
"build:electron:win": "electron-builder build --win",
"build:electron:mac": "electron-builder build --mac",
"build:mac": "yarn build:ui && yarn build:electron:mac",
"package:mac": "yarn build:ui && yarn build:electron:mac --publish never",
"package:win": "yarn build:ui && yarn build:electron:win"
}UI loading without problem but on routing I am getting the error that attachted as image.
output="export" generates .txt files and on production, router.push('/login') try to call file:///login/index.txt
How can I solve this?
8 Replies
@Mümin Celal Pinar I am trying to run NextJS 13 with Electron and application is working on development but when I try to build it I am struggling with routing. Routing is not working on production.
next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
reactStrictMode: true,
images: {
unoptimized: true
},
eslint: {
ignoreDuringBuilds: true
}
};
module.exports = nextConfig;
scripts
"scripts": {
"clean": "rimraf out dist .next",
"dev:ui": "rimraf out .next && next dev -p 3000",
"dev:electron": "electron .",
"start:ui": "next start",
"lint": "eslint src/**/*.{js,jsx} --fix",
"format": "prettier --write src/**/*.{js,jsx}",
"build:ui": "next build",
"build:electron:win": "electron-builder build --win",
"build:electron:mac": "electron-builder build --mac",
"build:mac": "yarn build:ui && yarn build:electron:mac",
"package:mac": "yarn build:ui && yarn build:electron:mac --publish never",
"package:win": "yarn build:ui && yarn build:electron:win"
}
UI loading without problem but on routing I am getting the error that attachted as image.
output="export" generates .txt files and on production, router.push('/login') try to call file:///login/index.txt
How can I solve this?
im guessing you are opening the html files withought a server as it is trying to access the root file (normally nextjs has everything prefixed with root to simplify on web)
So what should I do? Electron works file based after build.
@Mümin Celal Pinar So what should I do? Electron works file based after build.
Finnish Spitz
did you find any solution?
Unfortunately
@Mümin Celal Pinar Unfortunately
Finnish Spitz
i found a workaround i dont think it constitutes as a solution but. the workaround is to use traditional a tags or lowlevel browser api like window.location.href instead of methods provided by nextjs
What is it?
@Mümin Celal Pinar What is it?
Finnish Spitz
that is the workaround...
to use
<a href=""></a> tags or window.location.href = "/redirect-to"