microsoft / dts-gen

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

expression-file doesn't seem to work; 'Couldn't load module "undefined"' #65

Open mnpenner opened 7 years ago

mnpenner commented 7 years ago

I'm trying

dts-gen --expression-file ./index.js

But I get

Couldn't load module "undefined". Please install it globally (npm install -g undefined) and try again.

Which doesn't make much sense.

How can I generate a .d.ts file for my library without having to globally install it first?

trivikr commented 7 years ago

Hi, any update on this? I'm also facing similar issue while trying to generate .d.ts files

dtgriscom commented 6 years ago

I'm in the same boat. Any suggestions on what might be going wrong? (If it's caused by a specific line in the .js file, a line number would be great...)

DavidNorena commented 6 years ago

and your solution guys was ?

ayqy commented 5 years ago

@DavidNorena It's likely that there are relative path require() statements in expression-file, and would not be correctly resolved.

Just transform to absolute path to do the tricks, for example:

$ dts-gen -e "require('./dist/umd/emoutils.js')"
Couldn't load module "undefined". Please install it globally (npm install -g undefined) and try again.
# Change to Absolute Path
$ dts-gen -e "require('/absolute-path-to/emoutils.js')"
Wrote 52 lines to dts_gen_expr.d.ts.

Or dive into source and specify a correct cwd to fix this issue.

hotfix519 commented 5 years ago

I also encountered this issue. My issue was also with unresolved dependencies. I had not run npm install on the repo I was trying to run dts-gen on. After I did so, the issue resolved.