TypeScript - [Subsequent property declarations must have the same type] - Multiple references to the same type definitions
Because of the feedback above I believe I have found a solution to my problem.
- Run 'npm uninstall react -g' to uninstall the react package from your global cache.
Create a manual reference in your
package.json
file to the@types/react
package."devDependencies": { "@types/react": "16.4.13"}
My final package.json file looked like this:
{ "name": "fungalai", "version": "1.0.0", "dependencies": { "react": "16.4.2", "react-dom": "16.4.2" }, "devDependencies": { "@types/flux": "3.1.7", "@types/react": "16.4.13", "axios": "^0.18.0", "deep-diff": "^1.0.1", "babel-core": "^6.26.3", "babel-loader": "^7.1.4", "babel-polyfill": "^6.26.0", "babel-preset-es2015": "6.24.1", "babel-preset-react": "6.24.1", "babel-preset-stage-0": "^6.24.1", "create-react-class": "^15.6.3", "expose-loader": "^0.7.5", "jszip": "^3.1.5", "flux": "3.1.3", "ts-loader": "^4.3.0", "typescript": "3.0.1", "uglifyjs-webpack-plugin": "^1.2.5", "webpack": "^4.8.3", "webpack-cli": "^2.1.4" }}
and tsconfig.json like this:
{ "compilerOptions": { "module": "commonjs", "moduleResolution": "node", "target": "es5", "sourceMap": true, "jsx": "react", "lib": [ "es6", "dom" ], "removeComments": true, "typeRoots": [ "/node_modules/@types", "/Types/" ] }, "compileOnSave": false, "exclude": [ "/node_modules/", "/bin", "/obj" ]}
This seems to have resolved the errors.
I found the following github issue, which I am pretty certain identifies the root cause of the problems you were facing: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/25145
So you'll get @types/react at version 16.3.9 and @types/react-dom at version 16.0.5, because you explicitly asked for those. However, @types/react-dom lists a dependency on @types/react as the following:
"@types/react": "*"
[this] interprets as "the latest version of @types/react", so it installs an additional version of the package.
So you will have versions v16.3.9 and v16.3.12 of the types package simultaneously being used, which causes the error.
There's two ways I know of to fix this:
- Update to the latest version of the @types/react package in your package.json
- Add a resolutions section to your package.json to tell Yarn to resolve the dependency differently.
This error occurs when you have a dependency and a sub-module with the same dependency in a different version. The right way to fix this is including a "resolutions" section in your package.json
. The following example explain how to you "resolutions":package.json
{ "name": "project", "version": "1.0.0", "dependencies": { "left-pad": "1.0.0", "c": "file:../c-1", "d2": "file:../d2-1" }, "resolutions": { "d2/left-pad": "1.1.1", "c/**/left-pad": "^1.1.2" }}
Documentation reference: https://classic.yarnpkg.com/en/docs/selective-version-resolutions/