react-nodegui-starter icon indicating copy to clipboard operation
react-nodegui-starter copied to clipboard

NodeJS require

Open dawidpstrak opened this issue 4 years ago • 6 comments

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

dawidpstrak avatar May 05 '20 19:05 dawidpstrak

Sure, just like in any other nodejs or webpack app

Solant avatar May 05 '20 19:05 Solant

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

dawidpstrak avatar May 05 '20 19:05 dawidpstrak

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

Solant avatar May 05 '20 20:05 Solant

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

dawidpstrak avatar May 05 '20 20:05 dawidpstrak

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

Solant avatar May 05 '20 20:05 Solant

Ok cant setup it. Anyway thanks help.

dawidpstrak avatar May 05 '20 21:05 dawidpstrak