Reputation: 33650
I would like to upgrade a project to React 16, because I have some dependencies that already rely on it. However, I'm also tailing a few very old React packages that I have not found the time yet to upgrade to newer releases that do support React 16. Now I need to buy some time.
My project sources have kept up with the newer releases of React, but I wonder if there's anything that would not be possible to resolve for old dependencies that would cause them to remain completely broken with React 16?
Upvotes: 7
Views: 6486
Reputation: 904
Put this at the top of index.js (or your first file you load):
import './patchReact'
import React from 'react'
....
etc
// patchReact.js
require('react').PropTypes = require('prop-types')
require('react').createClass = require('create-react-class')
Credit to Dan Abramov's tweet.
Upvotes: 4
Reputation: 33650
Following this suggested comment, patching React early on by importing something like the following module before importing olden dependencies should work:
import React from 'react'
import PropTypes from 'prop-types'
import createClass from 'create-react-class'
Object.assign(React, {
PropTypes,
createClass
})
For projects that were receiving warnings prior to React 16, these then get resolved.
Upvotes: 9
Reputation: 917
So, first of all, upgrading the project with old dependency into React 16 is gonna break somewhere now or in near future until and unless you don't upgrade other dependencies in your project. But, I can suggest you a way by which you can bypass for quite some time.
{
"name": "project-name",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-scripts": "1.0.14"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Update your dependency of react with this given dependency and remove the node_modules folder and again fire npm install on your package.json to install the new packages for react run and test and build.
Upvotes: 1