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

fix: use global scope for metadata storage #928

Closed
petrzjunior opened this issue Sep 23, 2021 · 3 comments · Fixed by #929
Closed

fix: use global scope for metadata storage #928

petrzjunior opened this issue Sep 23, 2021 · 3 comments · Fixed by #929
Labels
status: fixed Issues with merged PRs, but not released yet type: fix Issues describing a broken feature.

Comments

@petrzjunior
Copy link
Contributor

Description

Currently, the type metadata are cached in MetadataStorage which is created src/storage.ts and exported. As long as this file is imported once, it works as intended. When importing (requiring) file, Node.js looks it up in the import cache so that the every file is not imported only once. This however relies on consistent file names and has some caveats as covered in the documentation. For instance file case sensitiveness or using symlinks inside node_modules. This behavior can lead to having more than one instance of MetadataStorage and failing to resolve the correct data types, consequently spitting up random errors.

Expected behavior

I expect class-transformer not to rely on importing logic. And creating a singleton storage.

Actual behavior

Singleton is not a true singleton and importing from symlinked locations causes it to create multiple instances.

@petrzjunior petrzjunior added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Sep 23, 2021
@soloyal
Copy link

soloyal commented Apr 8, 2022

Simple fix in storage.ts

const globalRef = global as any
export const defaultMetadataStorage = global.classTransformerMetadataStorage 
  || (global.classTransformerMetadataStorage = new MetadataStorage());

We are all waiting your new release with the fix!)

@y0gzah
Copy link

y0gzah commented Feb 1, 2023

This is still not fixed.
I'm using class-transformer class-validator class-sanitizier and routing-controllers in different packages of my project.
And decorators just don't exist at all from one package to the other.

@NoNameProvided NoNameProvided added status: fixed Issues with merged PRs, but not released yet and removed status: needs triage Issues which needs to be reproduced to be verified report. labels May 4, 2024
Copy link

github-actions bot commented Jun 4, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: fixed Issues with merged PRs, but not released yet type: fix Issues describing a broken feature.
4 participants