microsoft / dts-gen

dts-gen creates starter TypeScript definition files for any module or library.
MIT License
2.43k stars 102 forks source link

Unexpected crash: ReferenceError: window is not defined #83

Open wedi opened 6 years ago

wedi commented 6 years ago

Hi, I am experiencing an "Unexpected crash". Here is what I did:

> npm install -g dts-gen
> npm install -g vue2-dropzone
> dts-gen -m vue2-dropzone

and this is the result:

Unexpected crash! Please log a bug with the commandline you specified. C:\Users\dirk\AppData\Roaming\npm\node_modules\dts-gen\bin\lib\run.js:130 throw e; ^

ReferenceError: window is not defined at C:\Users\dirk\AppData\Roaming\npm\node_modules\vue2-dropzone\dist\vue2-dropzone.js:2:24488 at C:\Users\dirk\AppData\Roaming\npm\node_modules\vue2-dropzone\dist\vue2-dropzone.js:2:24420 at e.exports (C:\Users\dirk\AppData\Roaming\npm\node_modules\vue2-dropzone\dist\vue2-dropzone.js:2:24706) at Object.e.exports.e.webpackPolyfill.e.deprecate (C:\Users\dirk\AppData\Roaming\npm\node_modules\vue2-dropzone\dist\vue2-dropzone.js:2:25182) at t (C:\Users\dirk\AppData\Roaming\npm\node_modules\vue2-dropzone\dist\vue2-dropzone.js:1:404) at Object.e.exports.e (C:\Users\dirk\AppData\Roaming\npm\node_modules\vue2-dropzone\dist\vue2-dropzone.js:1:527) at t (C:\Users\dirk\AppData\Roaming\npm\node_modules\vue2-dropzone\dist\vue2-dropzone.js:1:404) at r (C:\Users\dirk\AppData\Roaming\npm\node_modules\vue2-dropzone\dist\vue2-dropzone.js:1:491) at C:\Users\dirk\AppData\Roaming\npm\node_modules\vue2-dropzone\dist\vue2-dropzone.js:1:496 at i.(anonymous function).exports (C:\Users\dirk\AppData\Roaming\npm\node_modules\vue2-dropzone\dist\vue2-dropzone.js:1:143)

aolney commented 6 years ago

Also had this error. Looks like the problem is that window is browser side. The README for dts-gen has a rather cryptic addendum at the bottom that worked for me with p5. Open a page that has the code running that you care about, open the developer console, paste this into console var s = document.createElement('script'); s.src = 'https://unpkg.com/dts-gen/bin/browser-bundle.js'; document.body.appendChild(s);, and then type in the name of the type you want to generate a definition for (in my case, p5).

Nyconing commented 5 years ago

Can you please giving more example on browser-side generation? What is p5? Is it window.p5? But out put declare const window.foo: any;

I found myself, please type window.foo.someclass

stereobooster commented 4 years ago

Solution

git clone https://github.com/microsoft/dts-gen.git
cd dts-gen
npx serve docs

Change the contents of docs/index.html to include libraries you need, for example

<!DOCTYPE html>
<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.5.1/leaflet.js" integrity="sha256-EErZamuLefUnbMBQbsEqu1USa+btR2oIlCpBJbyD4/g=" crossorigin="anonymous"></script>
    <script src="https://unpkg.com/leaflet-freedraw@2.12.0/dist/leaflet-freedraw.iife.js"></script>
  </head>
  <body>
    <ul>
      <div class="inferLink" onclick="infer('L')"><li>Leaflet</li></div>
      <div class="inferLink" onclick="infer('LeafletFreeDraw')"><li>FreeDraw</li></div>
    </ul>
    <script type="text/javascript" src="browser-bundle.js"></script>
  </body>
</html>

go to browser, enter name of lib you want, click generate

zhenwei12138 commented 4 years ago

How to generate private package?