chimurai / http-proxy-middleware

:zap: The one-liner node.js http-proxy middleware for connect, express, next.js and more
MIT License
10.76k stars 849 forks source link

[2.0.2] peerDependency warning with the new release #703

Closed AviVahl closed 2 years ago

AviVahl commented 2 years ago

Checks

Describe the bug (be clear and concise)

Latest version requires @types/express as a peerDependency, printing warnings for non-typescript projects as well.

Step-by-step reproduction instructions

mkdir testproxy
cd testproxy
yarn init -y
yarn add http-proxy-middleware

see message:
`warning " > http-proxy-middleware@2.0.2" has unmet peer dependency "@types/express@^4.17.13".`

Expected behavior (be clear and concise)

No warnings when installing package. Don't require users to install @types packages as if everyone is using typescript.

How is http-proxy-middleware used in your project?

via `webpack-dev-server`, like half the web.

What http-proxy-middleware configuration are you using?

Irrelevant

What OS/version and node/version are you seeing the problem?

Fedora 35; Node 16.13.2; yarn 1.22.17

Additional context (optional)

Regressed by https://github.com/chimurai/http-proxy-middleware/pull/700

chimurai commented 2 years ago

Hi thanks for your report.

Those types provide a better developer experience in your IDE with autocompletion; Also in non-typescript projects. With @types/express you'll get autocompletion of express' req and res objects, which was broken as reported here: https://github.com/chimurai/http-proxy-middleware/issues/692

Perhaps the yarn warning can suppressed by marking as optional:

  "peerDependenciesMeta": {
    "@types/express": {
      "optional": true
    }
  },

https://docs.npmjs.com/cli/v7/configuring-npm/package-json#peerdependenciesmeta

Marking a peer dependency as optional ensures npm will not emit a warning if the @types/express package is not installed on the host. This allows you to integrate and interact with a variety of host packages without requiring all of them to be installed.

I have to double check if this will solve the issue.

AviVahl commented 2 years ago

Specifying the peerDependenciesMeta field would indeed solve the warning, AFAIK.

aholtkamp commented 2 years ago

We are utilizing "http-proxy-middleware" (and "express") in a custom package which is meant to be used by other packages. It only provides a command in its package.json ("bin") which can be executed (no "js" / "typescript" coding involved).

Since the last change we now get the warning for every usage of our custom package. Does it really make sense to require adding "@types/express" to every usage of our package to resolve the warning? Seems contra intuitive to me. We could add "@types/express" to the normal dependencies of our custom package to avoid the warning but this feels weird as types are usually added as "devDependency"...

In addition to this I think it is not the job of "http-proxy-middleware" to enforce / require adding "@types/express". If it is anyones job "express" should do that (but I wouldn't encourage that either)...

Can you please revert this change?

chimurai commented 2 years ago

fixed in v2.0.3