Comments (8)
This is not needded.
peerdependencies are essentially a broken feature across the industry and we stay away from them.
from fastify-secure-session.
Disagree, but ok. :)
For future readers bumping into this. A dependency of some sort is needed for TypeScript because of the types here:
fastify-secure-session/types/index.d.ts
Lines 3 to 15 in bb23dc6
Here's the error you might bump into:
src/app.module.ts:67:30 - error TS2339: Property 'session' does not exist on type 'FastifyRequest<RouteGenericInterface, Server, IncomingMessage, FastifySchema, FastifyTypeProviderDefault, unknown, FastifyBaseLogger, ResolveFastifyRequestType<...>>'.
67 session: request.session,
~~~~~~~
That's because fastify
being augmented by those types is not guaranteed to be the same fastify
your app uses.
https://yarnpkg.com/advanced/rulebook/#packages-should-only-ever-require-what-they-formally-list-in-their-dependencies
https://pnpm.io/how-peers-are-resolved
This blocks this package from being usable with Yarn 2+ and pnpm.
A workaround for Yarn 2 is to add this to .yarnrc.yml
packageExtensions:
"@fastify/secure-session@*":
peerDependencies:
fastify: "*"
They cannot be a simple dependency because it will desync with whatever fastify
version will be used in the top-level project unless the package manager dedupes (which is also a bad idea for many reasons, but npm
does it automatically), so it has to be a peer.
from fastify-secure-session.
I think I am running into this issue as we speak. The error @andreialecu has mentioned, is the exact same issue I am running into after a simple pnpm install
. All the code works and this error came out of nowhere:
from fastify-secure-session.
An option would be adding a note in the README that only npm
will work out of the box. The README should at least point out users of yarn
and pnpm
to this thread or mention the workarounds directly. Alternatively, say that only npm
is supported and everyone else is on their own.
The correct fix would be adding the peer dependency, which carries the whole meaning of the relationship between the packages.
As for
peerdependencies are essentially a broken feature across the industry and we stay away from them.
If by the industry
it's meant just npm
, I'd agree. :)
from fastify-secure-session.
Adding the following section to my package.json
fixed this issue for me:
"pnpm": {
"packageExtensions": {
"@fastify/secure-session": {
"peerDependencies": {
"fastify": "*"
}
}
}
}
from fastify-secure-session.
@mcollina just fyi, if this RFC gets implemented in npm, as it has already been accepted, it will introduce a mode similar to pnpm and this issue will pop up there too: https://github.com/npm/rfcs/blob/main/accepted/0042-isolated-mode.md
from fastify-secure-session.
What makes this issue specific to this module? Every fastify module is implemented in the same way, and possibly there are some specific on what your setup is that cause this problem with types.
If this problem is not limited to this module, I recommend you to open an issue on the main repo with a complete reproduction, and we'll likely figure out a workaround that does not require the use of peerDependencies.
from fastify-secure-session.
I'm working around it so it's not a blocker by any means. I just wanted to bring more awareness to this issue.
I'm also not sure why the hate on peerDependencies
- the problems stemming from them derive from bad decisions npm
made, such as auto-installing them.
They serve a very important purpose, especially in mono repos and with workspaces. It's impossible to avoid them in such cases.
from fastify-secure-session.
Related Issues (20)
- "k\" must be crypto_secretbox_KEYBYTES bytes long HOT 2
- `.bin` is not registered when using yarn HOT 6
- New cookie is made on every request, even if session is unchanged HOT 2
- Multiple cookies HOT 2
- v5.3.0 breaks with `Cannot read properties of undefined (reading 'sign')"` HOT 4
- Segmentation Fault when using alpine image HOT 7
- Enable multiple cookie sessions HOT 5
- "No native build was found" HOT 3
- No native build was found - EsBuild AWS Lambda HOT 2
- Release new version to be type compatible with other `@fastify/cookie` modules HOT 1
- Update cookie expiration without updating data HOT 1
- i have been hack HOT 5
- Upgrade @fastify/cookie to 9.1.0 HOT 1
- Considering adding proprietary cookies good practices as Chrome make big changes on cookies in 2024 HOT 2
- typescript types don't work properly HOT 3
- changed value should be set to true when modifying objects within session HOT 1
- "reply.signCookie is not a function" when setting option signed: true HOT 2
- New "expiry" is not included in TypeScript definition HOT 2
- No way to update session expiration HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-secure-session.