Node version: v10.15.3
I'm working on a project. Everything worked fine, but after someone did npm install the following error is shown:
TypeError: Cannot call a class constructor without |new|
in SContainer.js
followed by:
The above error occurred in the <FluxContainer(SContainer)> component:
in FluxContainer(SContainer)
Consider adding an error boundary to your tree to customize error handling behavior.
I want to render a container with props, but apparently it doesn't work anymore. The way it was done is as follows:
search.js:
'use strict'
import React from 'react';
import ReactDOM from 'react-dom';
import SContainer from './containers/sContainer'
ReactDOM.render(
<SContainer page="search"/>,
document.getElementById('search')
);
and SContainer.js:
'use strict';
// import area
// framework related imports
import React from 'react';
import { Container } from 'flux/utils';
import {MuiThemeProvider} from '@material-ui/core/styles';
// application related imports
import ShopStore from './../../stores/shopStore';
import ContentContainer from './contentContainer';
import ProviderRegistration from '../../components/views/providerRegistration';
import ProviderServiceRegistration from '../../components/views/providerServiceRegistration';
// variables area
class SContainer extends React.Component {
constructor(props) {
super(props);
this.className = this.constructor.name;
this.state = {};
this.style = {
routerContent: {
flexGrow: 1
}
};
}
static getStores() {
let stores = [
ShopStore
];
return stores;
}
static calculateState(prevState) {
let state = {
shopStore : ShopStore.getState(),
}
return state;
}
render() {
const shopStore = this.state.shopStore;
const theme = shopStore.get('theme');
const renderPageObject = {
// /provider-page
"providerPage": <ProviderRegistration {...this.state} />,
// /search-page
"searchShop": <ContentContainer {...this.state} />,
// /service-registration
"serviceRegistration": <ProviderServiceRegistration {...this.state} />,
}
return (
<MuiThemeProvider theme={theme.object} >
<section className="container">
<div className='row app'>
<div className="col-sm-10">
<div id='routerContent' style={this.style.routerContent}>
{renderPageObject[this.props.page]}
</div>
</div>
</div>
</section>
</MuiThemeProvider>
);
}
}
export default Container.create(SContainer);
I found a workaround on github, which adviced to do something like this in the SContainer.js:
var fluxContainerConverter = require('./FluxContainerConverter');
export default Container.create(fluxContainerConverter.convert(ShopContainer));
and in FLuxContainerConverter.js:
module.exports = {
convert: function(containerClass) {
const tmp = containerClass;
containerClass = function(...args) {
return new tmp(...args);
};
containerClass.prototype = tmp.prototype;
containerClass.getStores = tmp.getStores;
containerClass.calculateState = tmp.calculateState;
return containerClass;
}
};
But this doesn't work either, I just get other errors, which ultimately lead to a Warning: Unexpected Fiber popped error. I'm pretty clueless about the error honestly so any help would be appreciated. If I forgot to post something important, let me know.
Here is the package.json:
{
"name": "project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build:dev": "webpack --config ./webpack.config.js --watch --progress --color",
"build:prod": "rm -rf build node_modules && npm i --unsafe-perm && webpack --config ./webpack-production.config.js --progress",
"yarn:prod": "rm -rf build node_modules && yarn install --unsafe-perm && webpack --config ./webpack-production.config.js --progress",
"build:preprod": "rm -rf build node_modules && npm i --unsafe-perm && webpack --config ./webpack.config.js --progress",
"yarn:preprod": "rm -rf build node_modules && yarn install && webpack --config ./webpack.config.js --progress",
"clean": "rimraf dist"
},
"author": "",
"license": "GPL",
"dependencies": {
"@material-ui/core": "^3.1.0",
"alt": "^0.18.4",
"axios": "^0.12.0",
"bcv-react-select": "^1.1.1",
"classnames": "^2.2.5",
"country-data": "0.0.29",
"dateformat": "^3.0.2",
"flux": "^3.1.3",
"history": "^4.7.2",
"immutable": "^3.8.2",
"jquery": "^3.3.1",
"material-design-icons": "^3.0.1",
"moment": "^2.14.1",
"online-event-tool": "1.0.2",
"react": "^16.8.6",
"react-addons-shallow-compare": "^15.2.1",
"react-addons-test-utils": "^15.6.2",
"react-avatar": "^3.4.3",
"react-copy": "^0.2.1",
"react-custom-scrollbars": "^4.2.1",
"react-dom": "^16.8.6",
"react-image-gallery": "^0.7.15",
"react-input-autosize": "^1.0.0",
"react-joyride": "^1.11.4",
"react-places-autocomplete": "^3.0.0",
"react-router-dom": "^4.2.2",
"react-select": "^1.0.0-beta14",
"react-slick": "^0.14.8",
"react-tabs": "^0.5.5",
"react-tap-event-plugin": "^1.0.0",
"sockjs-client": "^1.1.1",
"strip-loader": "^0.1.2",
"superagent": "^4.0.0-beta.5",
"unique-id-mixin": "^1.0.0",
"velocity-animate": "^1.4.2",
"velocity-react": "^1.2.1",
"vis": "^4.21.0",
"webpack-merge": "^4.1.0",
"xhr": "^2.4.1"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.9.1",
"babel-loader": "^6.2.4",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-3": "^6.24.1",
"css-loader": "^0.26.1",
"enzyme": "^3.2.0",
"enzyme-adapter-react-15": "^1.0.5",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^1.1.5",
"node-sass": "^4.5.0",
"react-addons-css-transition-group": "^15.5.2",
"react-controllables": "^0.6.0",
"react-pure-render": "^1.0.2",
"react-test-renderer": "^15.6.2",
"sass-loader": "^4.1.1",
"style-loader": "^0.13.1",
"transfer-webpack-plugin": "^0.1.4",
"uglifyjs-webpack-plugin": "^2.0.1",
"webpack": "^3.11.0",
"webpack-cli": "^3.1.0"
}
}
All right, after some while I figured it out. I basically had to update all react libraries and other stuff, because some of the naming conventions changed.