After typescript update 2.3.4 => 2.4.2 i get compilation error "Cannot find type definition file for 'reflect-metadata'."
Asked Answered
C

3

5

I have a React / Mobex application written in TypeScript, built by Webpack 1. After updating TypeScript version from 2.3.4 to 2.4.2 i get an error

ERROR in C:\myproject\tsconfig.json
error TS2688: Cannot find type definition file for 'reflect-metadata'.

I also tried Typescript 2.7.2, same error. I've tried explicitly providing the path to its typings in "paths", tried installing the latest version of 'reflect-metadata', including globally - still same error.

tsconfig.json

{
    "compilerOptions": {
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "jsx": "react",
        "lib": ["dom", "es2015.promise", "es6"],
        "module": "commonjs",
        "moduleResolution": "node",
        "noImplicitAny": true,
        //"noUnusedLocals": true,
        "noUnusedParameters": true,
        "outDir": "./dist/",
        "sourceMap": true,
        "suppressImplicitAnyIndexErrors": true,
        "target": "es5",
        "types": ["reflect-metadata"],
        "baseUrl": ".",
        "paths": {
            "react-split-pane": ["./type_fixes/react-split-pane/index.d.ts"],
            "react-dropzone": ["./type_fixes/react-dropzone/index.d.ts"],
            "react-bootstrap-toggle": ["./type_fixes/react-bootstrap-toggle/index.d.ts"]
        }
    },
    "include": [
        "./src/**/*",
        "./index.tsx",
        "./declarations.d.ts"
    ],
    "exclude": [
        "node_modules"
    ]
}

package.json

"dependencies": {
                //...
    "reflect-metadata": "0.1.10",
                //...
},
  "devDependencies": {
     //...
    "typescript": "2.4.2",
    //...
  },
Control answered 22/3, 2018 at 17:56 Comment(0)
S
6

Try to remove reflect-metadata from types section. You can import it as usual package:

import 'reflect-metadata'; // Just import to make visible Reflect

Reflect.defineMetadata(...)
Shayne answered 23/3, 2018 at 6:0 Comment(1)
This is what I ended up doing, switched to just "types": [].Control
A
2

Just for reference trying to solve the same error message when wanting reflect-metadata without import :)

npm i --save-dev @types/reflect-metadata

Solved it even though the message from installation says types are included with the reflect-metadata package.

Amieeamiel answered 25/8, 2021 at 18:52 Comment(0)
A
1

On my case, this happened when I upgraded typescript to version 5.

I had reflect-metadata inside tsconfig.json

"types": ["reflect-metadata"]

Just removed it solved, my problem.

Amethyst answered 5/8, 2023 at 14:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.