ecyrbe / zodios-plugins

plugins for zodios
MIT License
8 stars 3 forks source link

dom lib required for @zodios/plugins because of dom types in fetch plugin #136

Open JarnoRFB opened 1 year ago

JarnoRFB commented 1 year ago

First of all thanks for the great zodios library!

I am running node and using zodios in the backend.

After npm i @zodios/plugins and importing

import {pluginToken} from "@zodios/plugins";

I get the following errors from tsc

node_modules/@zodios/plugins/lib/fetch-plugin-5e8430b2.d.ts:6:12 - error TS2304: Cannot find name 'RequestMode'.

6     mode?: RequestMode;
             ~~~~~~~~~~~

node_modules/@zodios/plugins/lib/fetch-plugin-5e8430b2.d.ts:7:13 - error TS2304: Cannot find name 'RequestCache'.

7     cache?: RequestCache;
              ~~~~~~~~~~~~

node_modules/@zodios/plugins/lib/fetch-plugin-5e8430b2.d.ts:11:22 - error TS2304: Cannot find name 'ReferrerPolicy'.

11     referrerPolicy?: ReferrerPolicy;
                        ~~~~~~~~~~~~~~

node_modules/@zodios/plugins/lib/fetch-plugin-5e8430b2.d.ts:12:19 - error TS2304: Cannot find name 'RequestCredentials'.

12     credentials?: RequestCredentials;
                     ~~~~~~~~~~~~~~~~~~

node_modules/@zodios/plugins/lib/fetch-plugin-5e8430b2.d.ts:13:16 - error TS2304: Cannot find name 'RequestRedirect'.

13     redirect?: RequestRedirect;
                  ~~~~~~~~~~~~~~~

Found 5 errors in the same file, starting at: node_modules/@zodios/plugins/lib/fetch-plugin-5e8430b2.d.ts:6

The errors went away after adding

lib": ["dom", ...]

to tsconfig.json, but it seems a bit weird that I should have to add this to my backend. Is there any workaround for this or would it be an option to separate the plugins that should only be used for the browser into a separate package?

ecyrbe commented 1 year ago

yes, like it's mentionned on the documentation, there is no support for fetch on backend in zodios v10. If you can wait a little, zodios v11 will have native support for fetch on backend starting with node version 18.

JarnoRFB commented 1 year ago

Thanks for the update! My confusion was rather that I only wanted to use pluginToken but got errors from the fetch plugin. But since Node 18 is already LTS and will include the appropriate fetch types, it probably makes sense to just push people to upgrade.

ecyrbe commented 1 year ago

oh, that's one thing i did not think about. yes, the plugin token should work on backend and that is bad that zodios requires you to be compatible with fetch. Maybe i should create more fine grained exports in plugins packages, like import { pluginToken } from '@zodios/plugins/token', this should allow you to not rely on fetch plugin types when importing token plugin. i'll keep this opened and try to come with a fix for this.