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

Hapi auth jwt typescript bug #310

Open
vforv opened this issue May 9, 2019 · 14 comments
Open

Hapi auth jwt typescript bug #310

vforv opened this issue May 9, 2019 · 14 comments

Comments

@vforv
Copy link

vforv commented May 9, 2019

There is problem with types in last version.
when I do
tsc --traceResolution

get error:

node_modules/hapi-auth-jwt2/lib/index.d.ts(1,66): error TS2307: Cannot find module '@hapi/hapi'.

With old version: 8.1.0 works fine.

@xpolb01
Copy link

xpolb01 commented Jun 12, 2019

This affects previous versions too. Need a fix

@nelsonic
Copy link
Member

PRs very much welcome.

@xpolb01
Copy link

xpolb01 commented Jun 12, 2019

I like the practice "one who broke it fixes it".

I have version 8.1.0 installed in my package.json. When I delete node_modules and do a fresh install it gives me this error on build:

node_modules/hapi-auth-jwt2/lib/index.d.ts:1:66 - error TS2307: Cannot find module '@hapi/hapi'.

1 import { Request, ResponseObject, Plugin, ResponseToolkit } from '@hapi/hapi';

Most people use CI/CD, in our case we use Jenkins, so fresh build happens every time as well as this error.

My PR would be rolling back this PR https://github.com/dwyl/hapi-auth-jwt2/pull/307/files until this bug is fixed because it is breaking previous versions

@jaulz
Copy link
Contributor

jaulz commented Jun 13, 2019

@xpolb01 @vforv are you still using hapi package instead of @hapi/hapi?

@xpolb01
Copy link

xpolb01 commented Jun 13, 2019

@jaulz Yes, but even if I replace it with @hapi/hapi this is still an issue. I'm using Glue so I think that is what is causing the problem.
In Glue plugins are defined like this:

import  * as jwtAuth from 'hapi-auth-jwt2';
const jwtPlugin: Glue.Plugin = { plugin: jwtAuth, options: {} };

manifest
const manifest: Glue.Manifest = {
  server: {
    port: process.env.PORT || 5567,
    tls: tlsConfig,
  },
  register: {
    plugins: [jwtPlugin, apiPlugin, hapiBoomDecoratorsPlugin, sequelizePlugin],
  },
};

By the way, this only works if I user require instead of import. Otherwise it gives me an error:

  Type 'PluginBase<RegisterOptions> & PluginNameVersion' is not assignable to type 'string | { register: string; options?: any; }'.
    Type 'PluginBase<RegisterOptions> & PluginNameVersion' is not assignable to type '{ register: string; options?: any; }'.
      Types of property 'register' are incompatible.
        Type '(server: Server, options: RegisterOptions) => void | Promise<void>' is not assignable to type 'string'.ts(2322)

@jaulz
Copy link
Contributor

jaulz commented Jun 13, 2019

I think it should rather be import jwtAuth from 'hapi-auth-jwt2';.

@xpolb01
Copy link

xpolb01 commented Jun 13, 2019

In that case, I will get this error:


Module '"/Users/bogdan/Desktop/Work/betterpt-k8s/notification-service-k8s/node_modules/hapi-auth-jwt2/lib/index"' can only be default-imported using the 'esModuleInterop' flagts(1259)
index.d.ts(131, 1): This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' 

@jaulz
Copy link
Contributor

jaulz commented Jun 13, 2019

And what about this?

import  * as jwtAuth from 'hapi-auth-jwt2';
const jwtPlugin: Glue.Plugin = { plugin: jwtAuth.plugin, options: {} };

By the way, which hapi types are you using?

@xpolb01
Copy link

xpolb01 commented Jun 13, 2019

I'm using @types/hapi__hapi.
That won't work either cause, it says that it has no property plugin on it.

Error:

Property 'plugin' does not exist on type 'Plugin<RegisterOptions>'.
  Property 'plugin' does not exist on type 'PluginBase<RegisterOptions> & PluginNameVersion'.ts(233

@jaulz
Copy link
Contributor

jaulz commented Jun 13, 2019

Right, that was my fault. Which glue types are you using?

@xpolb01
Copy link

xpolb01 commented Jun 13, 2019

I use "@types/glue": "^5.0.3",

@jaulz
Copy link
Contributor

jaulz commented Jun 13, 2019

Then should you probably also use @hapi/glue.

@xpolb01
Copy link

xpolb01 commented Jun 13, 2019

Yep, that works.
But I think what I was trying to point to, that this forced me to update hapi, and the whole thing, even though I was using version 8.1. Service was working fine on development and then it suddenly started failing after restart. Somehow 8.6 affected previous versions which are in TS.

@nelsonic
Copy link
Member

nelsonic commented Mar 8, 2021

@xpolb01 / @jaulz still an issue?

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

No branches or pull requests

4 participants