Open phill2mj opened 7 years ago
Same here with
$ dts-gen -m image-capture
Unexpected crash! Please log a bug with the commandline you specified.
/usr/lib/node_modules/dts-gen/bin/lib/run.js:130
throw e;
^
ReferenceError: window is not defined
at /usr/lib/node_modules/image-capture/lib/imagecapture.js:62:45
at Object.defineProperty.value (/usr/lib/node_modules/image-capture/lib/imagecapture.js:5:5)
at Object.<anonymous> (/usr/lib/node_modules/image-capture/lib/imagecapture.js:13:3)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
the same
dts-gen -m browser-report Unexpected crash! Please log a bug with the commandline you specified. ...\AppData\Roaming\npm\node_modules\dts-gen\bin\lib\run.js:130 throw e;
^
ReferenceError: window is not defined
at ...\node_modules\browser-report\index.js:478:5
at Object.
I solved this by editing the file which was giving problems and adding the following to the top:
var window=window || {};
The generator then worked after this
@smac89 - Just one thing to add - You need to remove that line after the ts file has been created. If you don't remove the file [webpack/vendors file] will complain/fail if a function or field on the 'window' object is referenced; at this point the 'window' variable will be null.
The above fixed window, but started me down a rabbit hole of undefined navigator, document, Event, etc..
Here's fix that finally worked (add to top of file):
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const { window } = new JSDOM(``);
const { document, navigator } = window;
good~thanks!
If anyone is still having issues with this I took @easierbycode instructions and created a gist.
https://gist.github.com/ifiokjr/0e1e993f87a8f99b4924e8ecdce0edbc
The problem I was bumping into was
SecurityError: localStorage is not available for opaque origins
The fix is shown below:
const { JSDOM } = require('jsdom');
const DEFAULT_HTML = '<html><body></body></html>';
const jsdom = new JSDOM(DEFAULT_HTML, {
url: "https://www.bbc.co.uk",
referrer: "https://www.bbc.co.uk",
contentType: "text/html",
userAgent: "node.js",
includeNodeLocations: true
});
const { window } = jsdom;
const { document, navigator } = window;
I would say this is smarter:
// const Window = require('window');
// const window = new Window();
const navigator = require('navigator');
const { JSDOM } = require('jsdom');
const DEFAULT_HTML = '<html><body></body></html>';
const jsdom = new JSDOM(DEFAULT_HTML, {
url: "https://www.bbc.co.uk",
referrer: "https://www.bbc.co.uk",
contentType: "text/html",
userAgent: "node.js",
includeNodeLocations: true
});
const window = jsdom.window;
const document = jsdom.window.document;
dts-gen -m scrollmagic Unexpected crash! Please log a bug with the commandline you specified. /usr/local/lib/node_modules/dts-gen/bin/lib/run.js:120 throw e; ^
ReferenceError: window is not defined at /Users/mike/Documents/viewboard/node_modules/scrollmagic/scrollmagic/uncompressed/ScrollMagic.js:37:2 at /Users/mike/Documents/viewboard/node_modules/scrollmagic/scrollmagic/uncompressed/ScrollMagic.js:22:20 at Object. (/Users/mike/Documents/viewboard/node_modules/scrollmagic/scrollmagic/uncompressed/ScrollMagic.js:27:2)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)