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

fork-ts-checker-webpack-plugin tried to access typescript, but it isn't declared in its dependencies #497

Closed
abdes opened this issue Aug 5, 2020 · 10 comments
Labels

Comments

@abdes
Copy link

abdes commented Aug 5, 2020

Current behavior

When using fork-ts-checker-webpack-plugin as a dependency with strict package managers such as yarn berry, the following warning/error is issued:

(node:13248) [MODULE_NOT_FOUND] Error: fork-ts-checker-webpack-plugin tried to access typescript, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

This is actually due to the fact that fork-ts-checker-webpack-plugin does import 'typescript' but does not declare it in its peerDependencies.

Expected behavior

fork-ts-checker-webpack-plugin package.json should explicitly add typescript as a peer dependency.

Environment

  • fork-ts-checker-webpack-plugin: [5.0.14]
  • typescript: [3.9.7]
  • yarn: 2.1.1
@abdes abdes added the bug label Aug 5, 2020
@piotr-oles
Copy link
Collaborator

Hi! Thanks for reporting this issue. I'm afraid that even if we add typescript, there will be the same situation with eslint. And we don't want to have eslint in the peerDependencies as it's optional. Maybe we could add typescript and eslint to optionalDependencies? I'm not sure if yarn berry supports it

@abdes
Copy link
Author

abdes commented Aug 6, 2020

@piotr-oles
Copy link
Collaborator

I read a little bit more about optionalDependencies and it seems that they are not a solution for our case.

We combine typescript checking and eslint linting in one package. Because of that, we can't use peerDependencies for eslint. Also, there is an open PR to make typescript path configurable. This means we will resolve typescript path dynamically anyway. Is there any option to disable this warning for a certain use-case?

@abdes
Copy link
Author

abdes commented Aug 23, 2020

What I do to resolve this issue is to instruct yarn in .yarnrc.yml about that dependency:

packageExtensions:
  fork-ts-checker-webpack-plugin@*:
    peerDependencies:
      typescript: '*'

That silences the warning, but does not solve the issue. The thing is you do depend on typescript but you do not explicitly mention that...

@piotr-oles
Copy link
Collaborator

Not really - we can disable typescript and use only eslint. It was declared as a peerDependency before, but it was also an issue when you use it in a "config-only" packages (see #201). We will not change it, as it would show unwanted warnings for other packages, like create-react-app.

@ark120202
Copy link

It can be declared as an optional peer dependency using peerDependenciesMeta key

@phryneas
Copy link
Contributor

Following that documentation, only in combination with it being a peerDependency. Other bundlers don't know peerDependenciesMeta so every other package manager will still try to install it.

@phryneas
Copy link
Contributor

Also, "optional" just means "don't throw an error if it cannot be installed", not "do not install by default".

@ark120202
Copy link

Other bundlers don't know peerDependenciesMeta so every other package manager will still try to install it.

Both npm and pnpm support it for a while. Also peerDependenciesMeta can be used without an entry in peerDependencies, see yarnpkg/berry#531

Also, "optional" just means "don't throw an error if it cannot be installed", not "do not install by default".

It means both, since peer dependencies aren't being installed by default (though that might change in npm v7)

@abdes
Copy link
Author

abdes commented Aug 24, 2020

Not sure the closing of the issue without taking into account the clarification on peerDependenciesMeta is justified.

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

No branches or pull requests

4 participants