-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Main module not found in 3.0.0 (works in 2.1.0) #121
Comments
Hi @vytenisu, thanks for the report, I'm not seeing anything obvious. Do you have any idea what is causing this line in your 2.1.0 version?
I'm wondering if maybe you had set something up to get this working earlier. Or perhaps there was a feature in earlier versions that we did not realize existed. |
Did some testing on my project and remembered why I was using "--main" together with "--name" and also what "alias" is. Use case:
What happens: 2.1.0 (no --main and no --name) index.d.ts ends like this:
If you try to import such library, module will not be found based on TS. 2.1.0 (with --main and with --name) index.d.ts ends like this (alias is created):
Bundled library can successfully be imported. 3.0.0 (no --main and no --name) index.d.ts ends like this:
It does not work when importing library. Also "index" is not prefixed with library name because in 3.0.0 --name has to be used together with --main. In older versions --name was mandatory and could be used without --main. 3.0.0 (with --main and with --name) Error :)
So basically this "alias" is necessary for my use case. I have not looked into dts-generator code yet to understand the issue but above description should help understand the use case at least. |
Found the problem. Turns out I needed to also use:
Without this option prefix is converted to string as "undefined" here:
Which is a bug because without prefix "main" will never match under normal conditions. Maybe it is just me but even after fixing prefix locally I still could not generate a working .d.ts unless I provided module name as a prefix. Got confused a bit tbh :) This comment I found in source code explains code change history a bit:
|
Provided comment in PR by @msssk . Thank you! In the meantime I did something silly and after playing around a bit ended up publishing "npm-dts" and "npm-dts-webpack-plugin" packages. I wanted to have minimal configuration and simplicity for my use case. Should those packages be of any use for you or development of "dts-generator"- check them out. |
I found a simple method to make it works (as a temporary solution).
for expample: {
prefix: '',
name: 'demo',
main: '/index', // while the index.ts is your entry file.
} I hope I made myself clear :) |
For some reason, the mapping of declare module 'src/index' {
export class MyClass {}
export {};
}
declare module '@my-org/my-lib' {
// Missing export of MyClass here
} Make sure you have a default export on your main file. This way, the module will have the default export in it: declare module 'src/index' {
export class MyClass {}
export default MyClass;
}
declare module '@my-org/my-lib' {
export {default} from '/src/index';
} Also, keep in mind that if you're using @lemon-clown's temporary solution, you'll have to fix the |
Hello there!
First of all - thank you for the amazing package!
I have noticed that dts-generator stopped working for me in the new (3.0.0) version. I am running it on Windows.
Please see my experiment below:
Command line:
The text was updated successfully, but these errors were encountered: