nodegui / react-nodegui-starter

Starter repository for react based native desktop apps using react-nodegui
173 stars 31 forks source link

NodeJS require #133

Open dawidpstrak opened 4 years ago

dawidpstrak commented 4 years ago

HI. Is it possible to import library by const library = require('library') ?

Solant commented 4 years ago

Sure, just like in any other nodejs or webpack app

dawidpstrak commented 4 years ago

But i got this error when i try https://pasteboard.co/J70Fp6y.png

Solant commented 4 years ago

you should run 2 npm scripts at the same time: npm run start starts actual qode instance, while npm run dev starts webpack bundle for your js code

so you need to run both start and dev

UPD: both scripts should be running, if you need to restart app, you can just restart only npm run start task

dawidpstrak commented 4 years ago

Yes i have started both. Dev server is working but shown error : https://pasteboard.co/J70SV3F.png and when i try npm run start it cant start https://pasteboard.co/J70TCJr.png

It only happens when i ve my import lines in code

const memoryjs = require('memoryjs')
const processes = memoryjs.get.processes()
console.log(processes)

When i remove these lines app render without problems. It's not memoryjs issue because i dont have problem to require it in normal js file and run it with node filename.js

Solant commented 4 years ago

oh, I see now memoryjs has some native code that is prebuilt for specific nodejs version some additional steps may be required in this case, https://docs.nodegui.org/docs/guides/using-native-node-modules

or you can try different lib without prebuilt native binaries

dawidpstrak commented 4 years ago

Ok cant setup it. Anyway thanks help.