Build fails after e1fe1d264bc5363e008d23fea9d8c5d2ac0d8198
mat813 opened this issue · comments
Description
After upgrading to v7.7.3, my application fails to build with:
apps/index-generator.ts:156:22 - error TS2349: This expression is not callable.
Type '{ default: { (options: Options): RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>; (options: ((req: Request<...>) => boolean) | undefined): RequestHandler<...>; (middleware: RequestHandler<...>, options: Options): RequestHandler<...>; }; }' has no call signatures.
156 ? jwtHandler.unless(unlessOptions)
~~~~~~
node_modules/express-jwt/dist/index.d.ts:3:1
3 import * as expressUnless from 'express-unless';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.
Reproduction
const jwtHandler = expressjwt(jwtProperties);
app.use(jwtHandler.unless(unlessOptions));
The problem is from using import * as expressUnless from 'express-unless';
instead of import expressUnless from 'express-unless';
. When you use * as
the default export is available in .default
so you probably need to change https://github.com/auth0/express-jwt/blob/master/src/index.ts#L180 to middleware.unless = expressUnless.default;
.
Environment
- Version of this library used: v7.7.3
- Version of the platform or framework used, if applicable: nodejs v16.13.2
- Other modules/plugins/libraries that might be involved: typescript 4.7.2
Related to #291 , ping @ItzRabbs ... what should we do? 😱
Can you show me your tsconfig, please?
That's so odd, it works perfectly fine for me. In fact, doing import expressUnless from 'express-unless';
generated the error for me.
what if you use esModuleInterop: true
in your project?
BTW, is it common to rebuild stuff inside node_modules? I am kind of lost here
I don't have a choice on esModuleInterop
unfortunately.
Would you object if I try and PR into express-unless
and convert that to typescript? I think that would avoid the issues here.
@ItzRabbs not at all! I really appreciate your work and effort
Alright, I'll get to that today
My tsconfig has:
{
"compilerOptions": {
"target": "es2021",
"module": "commonjs",
"esModuleInterop": true,
"noImplicitAny": true,
"outDir": "./built",
"sourceMap": true,
"inlineSources": true,
"sourceRoot": "/",
"noEmitHelpers": true,
"importHelpers": true,
"resolveJsonModule": true,
"strictBindCallApply": true /* Enable strict 'bind', 'call', and 'apply' methods on functions. */,
"strictFunctionTypes": true /* Enable strict checking of function types. */,
"strictNullChecks": true
},
"types": ["jest", "jest-extended"],
"exclude": ["node_modules"],
"include": [
"apps/**/*.ts",
"actions/**/*.ts",
"actions-public/**/*.ts",
"mailers/**/*.ts",
"scripts/**/*.ts",
"ecosystem.json"
]
}
@jfromaniello Take a look at jfromaniello/express-unless#33 when you can
With the latest version of express-unless, I tried to do this:
import { unless } from 'express-unless';
but I get this:
'unless' can only be imported by using 'import unless = require("express-unless")' or by turning on the 'esModuleInterop' flag and using a default import.
@jfromaniello I was just about to reply to this. I think you're missing the dist folder in the latest release in npm.
Yes! that was it .. I just published a new version of express-unless including the missing files and it worked now
@mat813 can you try with express-jwt@7.7.4
? Thank you
I do see one issue with a missing RegExp type for path.url. Opened a PR: jfromaniello/express-unless#34
I'm getting build errors on the below
app.use(expressjwt({
secret: process.env.API_JWT_SECRET as string,
algorithms: ['HS256'],
getToken: req => req.getToken()
}).unless({
path: [
/^\/api(\/v\d+)?\/images/, // <--- this works okay
{ url: /^\/api(\/v\d+)?\/xref/, methods: ['GET'] }, // <--- this doesn't work right now
]
}))
ok! Updated in express-jwt@7.7.5
Looks good to me! Thanks for your help @jfromaniello
Hi,
So, renovate tried it, and my pipeline is still not happy with 7.7.5, I get
apps/index-generator.ts(121,26): error TS2694: Namespace '"/builds/.../node_modules/express-unless/dist/index"' has no exported member 'Options'.
but I guess it is because express-unless changed, and I need to change my
import type { Options } from 'express-unless';
to something else.
After a quick look at the code, it would be nice if the Params
type in express-unless was exported, otherwise I'm going to have to do something like Parameters<typeof unless>[0]
.
hi @mat813 , I just pushed express-unless@2.1.0
which export the type Params
Thank you all, with express-unless@2.1.0
I was able to update to express-jwt@7.7.5
.