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

Reflect.metadata is not a function #145

Open
andrzejkupczyk opened this issue Jun 22, 2023 · 5 comments · May be fixed by leonardfactory/babel-plugin-transform-typescript-metadata#70
Open

Comments

@andrzejkupczyk
Copy link

andrzejkupczyk commented Jun 22, 2023

Environment

node v16.20.0 (npm v8.19.4)

Reproduction

Run npm audit fix within the Nuxt 2 project and try to build the app.

Describe the bug

The reflect-metadata dependency is missing.

Additional context

I was able to solve this issue by adding the reflect-metadata dependency to my project and importing it. It seems that this is related to the v1.17.2 patch, specifically the addition of support to emit decorator metadata (#119). My suspicion is that reflect-metadata should not be included in the dev dependencies.

Logs

FATAL  Reflect.metadata is not a function
@pi0
Copy link
Member

pi0 commented Jun 22, 2023

Hi dear @andrzejkupczyk. Is is possible for your to make a small reproduction repo?

@andrzejkupczyk
Copy link
Author

Hey @pi0, thank you for the prompt reply. Alright, I'll work on preparing such a repository when I have some free time. Thanks!

@sirenkovladd
Copy link

package.json

{
  "name": "jiti-145",
  "author": "Sirenko Vlad",
  "devDependencies": {
    "jiti": "^1.19.1",
    "typescript": "^5.1.6"
  }
}

index.ts

function define(target: unknown, _: unknown) {
};

@define
export class Test {
  constructor() {
  }
}
❯ npx jiti index.ts
<cut>/jiti-145/node_modules/jiti/lib/index.js:2
  throw err; /* ↓ Check stack trace ↓ */
  ^

TypeError: Reflect.metadata is not a function
    at <cut>/jiti-145/index.ts:5:24
    at evalModule (<cut>/jiti-145/node_modules/jiti/dist/jiti.js:1:255106)
    at jiti (<cut>/jiti-145/node_modules/jiti/dist/jiti.js:1:253034)
    at Object.<anonymous> (<cut>/jiti-145/node_modules/jiti/bin/jiti.js:16:1)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.17.0

@andrzejkupczyk
Copy link
Author

Thanks a bunch, @sirenkovladd! ❤️

@sirenkovladd
Copy link

@pi0 maybe it would be better to fork babel-plugin-transform-typescript-metadata and solve this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants