lenny lenny - 22 days ago 8
TypeScript Question

NW.js + TypeScript: Cannot find module 'nw.gui'

I am trying to use TypeScript in an existing NW.js + JS project.

Since I am new to NW.js, I naively assumed it works out of the box after installing the nw.gui typings.

It doesn't (as TypeScript does not recognize the global

nw
variable).

import * as nw from 'nw.gui';


Gives me


Cannot find module 'nw.gui'


How do I setup my code to work properly with NW.js?

Answer

Workaround which lets me use the global nw variable from NW.js: declare var nw: any;

The compiler doesn't complain anymore. I don't get any type information, but I can live with that and just use it as I would in JS.