Closed mp3846 closed 4 months ago
As discussed in this bug #909 some variables should be initialized first (for react it should be inside index.js)
import { BrowserRouter } from 'react-router-dom'
import { StrictMode } from 'react'
import App from './App'
import authInfo from '<AppName>/.tmp/auth_info.json' // using a symlink to access folders outside src
import ReactDOM from 'react-dom/client'
const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(
<StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
</StrictMode>
)
if (process.env.NODE_ENV === 'development') {
window.NL_PORT = authInfo.port
window.NL_TOKEN = authInfo.accessToken
window.NL_ARGS = []
}
window.Neutralino.init()
Now we can access Neutralino API but still predefined global variables like NL_OS
or NL_CWD
are undefined!
Now we can access Neutralino API but still predefined global variables like
NL_OS
orNL_CWD
are undefined!
I found a fix for Vite but you can edit my fix according to the build tool you're using, https://github.com/neutralinojs/neutralinojs/issues/909#issuecomment-1374735839
I think you can solve the issue by using the window.
prefix while accessing global variables. Please use the latest neu CLI version which doesn't ask you to manually use the --frontend-lib-dev
flag. Thanks :tada:
After enabling Hot Reload and running
neu run --frontend-lib-dev
Hot Reloading works fine but I can not access global variables likeNL_OS
!Here is the result of running Demo project:
After running
neu run --frontend-lib-dev --window-enable-inspector
I get this error in the console:Every thing is OK when I just run
neu run
(native API is accessible)