Skip to content
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

[Case Study] Can't find tslib with rollup-plugin-typescript2 #2140

Closed
brandon-leapyear opened this issue Nov 18, 2020 · 5 comments
Closed

[Case Study] Can't find tslib with rollup-plugin-typescript2 #2140

brandon-leapyear opened this issue Nov 18, 2020 · 5 comments
Assignees
Labels
case study Package compatibility report

Comments

@brandon-leapyear
Copy link

brandon-leapyear commented Nov 18, 2020

What package is covered by this investigations?

  • rollup
  • rollup-plugin-typescript2

Describe the goal of the investigation

Why does rollup fail?

Investigation report

Related: ezolenko/rollup-plugin-typescript2#12
Minimal repro: https://github.com/brandon-leapyear/yarnpkg-berry-repro-2140

I'm getting an error like

[!] (plugin rpt2) Error: /Users/bchinn/Desktop/foo/index.ts(3,16): semantic error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.

Which is odd to me because rollup-plugin-typescript2 declares tslib as a dependency (link). I can solve the error by adding tslib to my own devDependencies, but I'm wondering if that's the actual solution, or if there's something else going on.

@brandon-leapyear brandon-leapyear added the case study Package compatibility report label Nov 18, 2020
@SagnikPradhan
Copy link
Contributor

SagnikPradhan commented Nov 18, 2020

Probably because the plugin uses your work-space's typescript which does not have access to the plugin's dependencies?

@brandon-leapyear
Copy link
Author

brandon-leapyear commented Nov 18, 2020

This is an old work account. Please reference @brandonchinn178 for all future communication


Even if the plugin is the one calling require('typescript')?
https://github.com/ezolenko/rollup-plugin-typescript2/blob/5ce7676ad0451df81e61190d42694f97085111fc/src/index.ts#L73

@SagnikPradhan
Copy link
Contributor

SagnikPradhan commented Nov 18, 2020

Yep, because plugin has typescript declared as peer dependency.

@brandon-leapyear
Copy link
Author

brandon-leapyear commented Nov 18, 2020

This is an old work account. Please reference @brandonchinn178 for all future communication


I see. So unless the plugin moves typescript into dependencies, there's no way around the user needing to install tslib? If that's the case, I'll make a PR on the plugin adding this step for pnp environments

@merceyz
Copy link
Member

merceyz commented Nov 18, 2020

I can solve the error by adding tslib to my own devDependencies, but I'm wondering if that's the actual solution, or if there's something else going on.

That is the correct solution, TypeScript is trying to resolve tslib from your package so it is the one that needs to declare it. The same is true for other package managers but hoisting magically makes it work though it's inherently broken https://yarnpkg.com/advanced/rulebook#packages-should-only-ever-require-what-they-formally-list-in-their-dependencies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
case study Package compatibility report
Projects
None yet
Development

No branches or pull requests

4 participants