passport types not exists when using ESM + Typescript
rluvaton opened this issue · 1 comments
rluvaton commented
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.15.0
Plugin version
2.2.0
Node.js version
18
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
13.2.1
Description
When using ESM with TypeScript the types are missing.
Example with this code:
import fastifyPassport from '@fastify/passport';
fastifyPassport.initialize()
fastifyPassport.secureSession()
fastifyPassport.use(undefined as any, undefined as any);
I get:
$ tsc --notEmit
src/index.ts:3:17 - error TS2339: Property 'initialize' does not exist on type 'typeof import("<repo-path>/node_modules/@fastify/passport/dist/index")'.
3 fastifyPassport.initialize()
~~~~~~~~~~
src/index.ts:4:17 - error TS2339: Property 'secureSession' does not exist on type 'typeof import("<repo-path>/node_modules/@fastify/passport/dist/index")'.
4 fastifyPassport.secureSession()
~~~~~~~~~~~~~
src/index.ts:6:17 - error TS2339: Property 'use' does not exist on type 'typeof import("<repo-path>/node_modules/@fastify/passport/dist/index")'.
6 fastifyPassport.use(undefined as any, undefined as any);
~~~
Found 3 errors in the same file, starting at: src/index.ts:3
Steps to Reproduce
or:
- run:
npm init -y
npm i typescript fastify @fastify/passport @types/node
./node_modules/.bin/tsc --init
- add this to
src/index.ts
file:
import fastifyPassport from '@fastify/passport';
fastifyPassport.initialize()
fastifyPassport.secureSession()
fastifyPassport.use(undefined as any, undefined as any);
- Add
"type": "module"
inpackage.json
- in
tsconfig.json
replace"module": "commonjs"
with"module": "Node16"
- run
tsc
Expected Behavior
should compile without errors
rluvaton commented
My bad, I also needed to add "moduleResolution": "Node"
to the tsconfig compilerOptions
{
// ...
"compilerOptions": {
// ...
"moduleResolution": "Node",
"module": "Node16",
}
}