`build` script fails when trying to use `getPath('userData')`
See original GitHub issueIf you change the start.js
file in master
to the following:
import {app, remote} from 'electron'
const userDataPath = app ? app.getPath('userData') : remote.app.getPath('userData')
export default () => (
<section>
<p>{'This is Next.js speaking'}</p>
<p>{`Your user data path is: ${userDataPath}`}</p>
</section>
)
When you run npm run build
, it will produce the following error.
> electron-next-skeleton@1.0.0 build /Users/manovotny/Developer/electron-next-skeleton
> next build renderer && next export renderer
> Using "webpack" config function defined in next.config.js.
using build directory: /Users/manovotny/Developer/electron-next-skeleton/renderer/.next
exporting path: /start
TypeError: Cannot read property 'app' of undefined
at Object.<anonymous> (/Users/manovotny/Developer/electron-next-skeleton/renderer/.next/dist/pages/start.js:15:88)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at _callee$ (/Users/manovotny/Developer/electron-next-skeleton/node_modules/next/dist/server/require.js:33:46)
at tryCatch (/Users/manovotny/Developer/electron-next-skeleton/node_modules/next/node_modules/regenerator-runtime/runtime.js:65:40)
I think I am doing the if check for which app to use correctly because the page could be server or client rendered.
To be clear, npm start
runs just fine without any errors. It’s only when you try and build that it’s unhappy.
I would appreciate any help or thoughts of what to try instead.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
App.getPath("userData") seems to give the wrong path
I'm trying to use nedb and pass it in my userData path. My Package.json "name": "my-electron-app", "version": ...
Read more >electron-json-storage - npm
Start using electron-json-storage in your project by running `npm i ... getPath('userData') value from the main process to your renderer ...
Read more >Scripting API: Application.persistentDataPath - Unity - Manual
When you build the Unity application, a GUID is generated that is based on the Bundle Identifier. This GUID is part of persistentDataPath....
Read more >Troubleshoot eksctl issues with EKS cluster and node group
When I use eksctl to create or update my Amazon Elastic Kubernetes Service ... See, How do I resolve cluster creation errors in...
Read more >Manage user data folders - Microsoft Edge Development
Some errors are unrecoverable, such as Access Denied when trying to use a user data folder that you don't have Write permissions to....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@leo yeah, I’m not saying it was your fault or that you didn’t explain it well. I’m saying I’m dense and finally get it now. 😊 Thanks again!
👋
Don’t try to render anything server-side. There’s no point in that as – for production – a static bundle will be generated. In addition, don’t assume that the server side of the renderer process is equal to the main process, I think they’re two separate processes. 😊
Only do that kind of stuff in the “client” part of the renderer process, not on the server. So make sure to check for the existence of
document
to ensure you’re on the client.