Repository created to address fastify/fastify#2404.
cd csj
orcd esm
npm i
npm start
- Test csj folder build using http://127.0.0.1:8000, and http://127.0.0.1:9000 for the esm folder.
- I have created two folders to highlight how TypeScript behaves when
esModuleInterop
is either true or false. - I locked fastify and plugin versions to versions that match the problem being discussed in afore-mentioned GitHub issue.
- For csj folder I copied the types for all 4 plugins used into the typings folder and ensured the default export is done using the
export =
form becauseexport default
does not work when"esModuleInterop": false
.- For
fastify-cookie
I also modified the types to move the named exports into a declared namespace (declare namespace fastifyCookie {...}
). - For
fastify-session
I also had to modify the types (copied from here) because installed types are not compatible with fastify v3. - For
fastify-websocket
I copied the types from this pull request: fastify/fastify-websocket#73
- For
- For the esm folder I used the official types because they use the
export default
form which works with"esModuleInterop": true
.
IMPORTANT to note that the fastify-session
import in the esm folder uses the same types from the csj folder (see paths
property in ./esm/tsconfig.json). The point of this is to show that export =
works regardless if esModuleInterop
is true or false, whilst export default
works on when esModuleInterop
is true.