strothj / react-docgen-typescript-loader

Webpack loader to generate docgen information from Typescript React components.
Other
360 stars 47 forks source link

Not working when used with typescript config using module: "esnext" #4

Closed thupi closed 6 years ago

thupi commented 6 years ago

Hi,

This tools really makes storybook way more useful for typescript users like me. However, when i tried to implement this into my react application which is built with create-react-app-typescript the proptypes was not extracted.

After a few ours of debugging i discoverred that the this package wouldn't work as long as my tsconfig.compilerOptions.module was set to "esnext". It works nicely when it is "CommonJS" instead. I dont know why this behavior is as it is but i think it might have to be fixed or at least mentioned in the docs in order to save other people some time :-)

strothj commented 6 years ago

Hello,

Thank you for the report. I have another report on this same issue.

The current implementation relies on inserting the docgen code after Webpack has already compiled through ts-loader.

I have a Webpack loader in development under the feature/add-loader branch which should solve this problem. I'm going to be reading the code before it hits the compiler, make the modification, then let the normal compiler process take over. The generated code I'll be inserting is built using the TypeScript compiler and AST.

I expect a release in the new couple of day if all goes well.

I will go ahead and make the changes to the docs : -)

thupi commented 6 years ago

Thanks for the quick response :-) ! My bad, forgot to check whether is was reported.

Good to hear, looking forward to that :-) !

msreekm commented 6 years ago

was this fix already merged?

strothj commented 6 years ago

@msreekm

Sorry for the confusion, this was taken care of by releasing as a new package. The method used to modify the code output was changed to resolve this problem.

If you're using react-docgen-typescript-webpack-plugin, change it out for react-docgen-typescript-loader (this is now the default when visiting this repo). The old package operated on the emitted source code and ran into issues like this. The loader method, the new one uses, avoids the problem by operating on the original source.