Component can't be used as JSX component - reactjs

After updating some of the legacy code from to node 16 and react 17.0.2 I have started getting this error in the React.FC component. 'WarningIcon' cannot be used as a JSX component.
My component Looks like this:
import { SvgIconProps } from '#material-ui/core/SvgIcon';
import { WithStyles, withStyles } from '#material-ui/core/styles';
import ReportProblemIcon from '#material-ui/icons/ReportProblem';
import classNames from 'classnames';
import * as React from 'react';
type TStyleRules = 'root' | 'defaultColor';
const styles = () => ({
root: {
'&$defaultColor': {
color: string,
},
},
defaultColor: {},
});
// tslint:disable-next-line:variable-name
const WarningIcon: React.FC<SvgIconProps & WithStyles<TStyleRules>> = ({
classes,
className,
...props
}) => (
<>
<ReportProblemIcon
className={classNames(classes.root, className, {
[classes.defaultColor]: !props.color || props.color === 'primary',
})}
{...props}
/>
</>
);
export default withStyles(styles)(WarningIcon);
When I call this component in my main component.
<WarningIcon className='some-random-class' />
Complete error Message:
TS2786: 'WarningIcon' cannot be used as a JSX component.
Its element type 'ReactElement<any, any> | Component<Pick<{ children?: ReactNode; color?: "error" | "inherit" | "disabled" | "action" | "primary" | "secondary" | undefined; fontSize?: "default" | ... 4 more ... | undefined; htmlColor?: string | undefined; shapeRendering?: string | undefined; titleAccess?: string | undefined; viewBox?...' is not a valid JSX element.
value in package.json
{
"name": "sample-app",
"version": "2.0.1",
"private": true,
"proxy": "http://localhost:5000",
"engines": {
"node": ">= 16.0.0"
},
"dependencies": {
"#hapi/basic": "^6.0.0",
"#hapi/good": "^9.0.1",
"#hapi/hapi": "^18.2.0",
"#hapi/inert": "6.0.0",
"#hapi/nes": "11.0.0",
"#hapi/vision": "^5.5.4",
"#material-ui/core": "^4.12.2",
"#material-ui/icons": "^4.11.2",
"#sc-devops/ux-theme": "^0.0.8",
"axios": "^0.21.1",
"badwords-list": "^1.0.0",
"boom": "^7.3.0",
"classnames": "^2.3.1",
"dotenv": "^10.0.0",
"file-saver": "^2.0.5",
"hapi-auth-jwt2": "^10.2.0",
"hapi-good-winston": "^3.0.1",
"hapi-require-https": "^5.0.0",
"hapi-swagger": "^14.2.1",
"joi": "^17.4.2",
"js-yaml": "^4.1.0",
"json2csv": "^5.0.6",
"jsonwebtoken": "^8.5.1",
"jszip": "^3.6.0",
"kafkajs": "^1.15.0",
"ldapjs": "^2.3.0",
"lodash": "^4.17.21",
"material-ui-chip-input": "^2.0.0-beta.2",
"memory-cache": "^0.2.0",
"node-cache": "^5.1.2",
"passport-saml": "^3.1.2",
"pg": "^8.7.1",
"pg-hstore": "^2.3.4",
"raf": "^3.4.1",
"react": "^17.0.2",
"react-ace": "^9.4.1",
"react-beautiful-dnd": "^13.1.0",
"react-dom": "^17.0.2",
"react-loadable": "^5.5.0",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "^4.0.3",
"react-select": "^4.3.1",
"redux": "^4.1.0",
"redux-thunk": "^2.3.0",
"sequelize": "^6.6.5",
"swagger-ui": "^3.51.1",
"tunnel": "^0.0.6",
"uuid": "^8.3.2",
"winston": "^3.3.3",
"yauzl": "^2.10.0"
},
"scripts": {
"start-server": "concurrently --kill-others \"webpack --mode development --progress --watch\" \"nodemon build/main.js\"",
"start-client": "react-scripts start",
"start": "concurrently --kill-others \"yarn start-server\" \"yarn start-client\"",
},
"jest": {
"collectCoverageFrom": [
"src/**/*.ts",
"src/**/*.tsx",
"!src/**/*.test.ts",
"!src/**/types/*.ts",
"!src/**/*.test.tsx",
"!src/typings.d.ts",
"!src/db/**/*"
]
},
"devDependencies": {
"#types/ace": "^0.0.44",
"#types/bluebird": "^3.5.36",
"#types/boom": "^7.3.1",
"#types/enzyme": "^3.10.8",
"#types/file-saver": "^2.0.3",
"#types/hapi__hapi": "^20.0.2",
"#types/hapi__nes": "^11.0.4",
"#types/jest": "^26.0.14",
"#types/js-yaml": "^4.0.2",
"#types/json2csv": "^5.0.3",
"#types/jsonwebtoken": "^8.5.4",
"#types/jszip": "^3.4.1",
"#types/ldapjs": "^2.2.0",
"#types/lodash": "^4.14.171",
"#types/memory-cache": "^0.2.1",
"#types/node": "^14.14.9",
"#types/query-string": "^6.3.0",
"#types/react": "^17.0.15",
"#types/react-beautiful-dnd": "^13.0.0",
"#types/react-document-title": "^2.0.4",
"#types/react-dom": "^17.0.9",
"#types/react-loadable": "^5.5.4",
"#types/react-redux": "^7.1.18",
"#types/react-router": "^5.1.16",
"#types/react-router-dom": "^5.1.8",
"#types/react-select": "^4.0.17",
"#types/redux-logger": "^3.0.9",
"#types/sequelize": "^4.28.10",
"#types/tunnel": "^0.0.3",
"#types/uuid": "^8.3.1",
"#types/winston": "^2.4.4",
"#types/yauzl": "^2.9.2",
"axios-mock-adapter": "^1.19.0",
"chokidar": "^3.5.2",
"concurrently": "^6.2.0",
"cross-env": "^7.0.3",
"enzyme": "^3.11.0",
"#wojtekmaj/enzyme-adapter-react-17": "^0.6.3",
"nodemon": "^2.0.12",
"prettier": "^2.3.2",
"redux-logger": "^3.0.6",
"sequelize-cli": "^6.2.0",
"ts-loader": "^9.2.5",
"tslint-config-airbnb": "^5.11.2",
"tslint-config-prettier": "^1.18.0",
"typescript": "4.3.5",
"webpack": "^5.50.0",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2",
"webpack-node-externals": "^3.0.0"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"eslintConfig": {
"extends": [
"react-app"
]
}
}

Related

Component cannot be used as JSX Component. Its Instance type is not a valid JSX element

Yesterday, in a separate folder, I initialized CRA + installed Material UI. Unfortunately (I think) this made me sprinkle the rest of the projects in separate folders.
I think I've searched all over the internet. I used "resolutions", nothing helps.... Of course, I cloned the repository, removed node modules, installed again and so on.
package.json file:
"name": "app",
"version": "3.1.4",
"private": true,
"typings": "./src/types.d.ts",
"engines": {
"node": "16.16.0"
},
"dependencies": {
"#ant-design/icons": "4.3.0",
"#craco/craco": "6.4.5",
"#dnd-kit/core": "4.0.0",
"#dnd-kit/sortable": "5.0.0",
"#honeybadger-io/js": "^4.7.1",
"#honeybadger-io/react": "^4.7.1",
"#react-pdf/renderer": "2.0.21",
"#stripe/react-stripe-js": "1.1.2",
"#stripe/stripe-js": "1.11.0",
"#types/big.js": "^6.1.3",
"#types/slug": "^5.0.3",
"antd": "4.10.2",
"antd-country-phone-input": "3.4.3",
"apexcharts": "3.23.1",
"axios": "0.21.2",
"big.js": "^6.1.1",
"craco-alias": "2.1.1",
"craco-less": "1.17.0",
"dompurify": "2.2.6",
"dotenv-cra": "3.0.1",
"draft-js": "0.11.7",
"draftjs-to-html": "0.9.1",
"event-source-polyfill": "1.0.24",
"file-saver": "2.0.5",
"formik": "2.2.9",
"framer-motion": "4.1.3",
"handlebars": "4.7.7",
"history": "4.10.0",
"html2canvas": "^1.3.2",
"jest": "26.6.0",
"js-levenshtein": "^1.1.6",
"jsonwebtoken": "8.5.1",
"linkifyjs": "2.1.9",
"luxon": "1.26.0",
"polished": "4.1.2",
"prettier-plugin-organize-imports": "^3.0.0",
"query-string": "6.13.7",
"react": "^17.0.2",
"react-apexcharts": "1.3.7",
"react-cookie": "^4.1.1",
"react-dom": "17.0.2",
"react-draft-wysiwyg": "1.14.6",
"react-grid-layout": "^1.3.4",
"react-intl": "5.10.1",
"react-lines-ellipsis": "^0.15.3",
"react-portal": "^4.2.1",
"react-query": "^3.39.1",
"react-router-dom": "5.2.0",
"react-scripts": "4.0.3",
"slug": "^5.2.0",
"smart-timeout": "2.5.2",
"source-map-explorer": "^2.5.3",
"styled-components": "5.2.1",
"talkjs": "0.14.5",
"ts-jest": "26.4.4",
"typescript": "^4.6.4",
"use-react-screenshot": "^1.0.2",
"uuid": "^8.3.2",
"web-vitals": "0.2.4",
"webpack": "4.44.2",
"yup": "^0.32.9"
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick"
}
},
"scripts": {
"start": "npm i",
"dev": "craco start",
"build": "craco --max_old_space_size=5120 build",
"eject": "craco eject",
"lint": "eslint --ext .ts \"src/**/*\"",
"format": "prettier --write \"src/**/*\"",
"test": "REACT_APP_ENV=test jest --config ./jest.config.js --env=jest-environment-jsdom",
"test:watch": "REACT_APP_ENV=test jest --config ./jest.config.js --watch --env=jest-environment-jsdom",
"test:ci": "REACT_APP_ENV=test jest --config ./jest.config.js --ci --changedSince=origin/master --forceExit --env=jest-environment-jsdom --coverage",
"version": "conventional-changelog -p emojis -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
"release": "release-it",
"analyze": "source-map-explorer 'build/static/js/*.js'"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
"defaults",
">0.2%",
"not dead"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#babel/core": "7.12.3",
"#babel/plugin-proposal-private-property-in-object": "^7.18.6",
"#testing-library/jest-dom": "5.11.6",
"#testing-library/react": "11.1.2",
"#testing-library/react-hooks": "^7.0.2",
"#testing-library/user-event": "12.2.2",
"#types/axios": "0.14.0",
"#types/dompurify": "2.2.1",
"#types/draft-js": "0.11.5",
"#types/draftjs-to-html": "0.8.0",
"#types/file-saver": "2.0.3",
"#types/handlebars": "4.1.0",
"#types/history": "4.7.6",
"#types/jest": "26.0.15",
"#types/js-levenshtein": "^1.1.1",
"#types/jsonwebtoken": "8.5.0",
"#types/linkifyjs": "2.1.3",
"#types/lodash.isequal": "4.5.5",
"#types/lodash.uniqueid": "4.0.6",
"#types/luxon": "1.26.0",
"#types/node": "12.0.0",
"#types/query-string": "6.3.0",
"#types/react": "17.0.2",
"#types/react-dom": "17.0.11",
"#types/react-draft-wysiwyg": "1.13.1",
"#types/react-grid-layout": "^1.3.2",
"#types/react-helmet": "6.1.0",
"#types/react-intl": "3.0.0",
"#types/react-lines-ellipsis": "^0.15.1",
"#types/react-portal": "^4.0.4",
"#types/react-router-dom": "5.1.7",
"#types/react-slick": "^0.23.10",
"#types/styled-components": "5.1.7",
"#types/uuid": "^8.3.1",
"#types/yup": "^0.29.13",
"#typescript-eslint/eslint-plugin": "4.7.0",
"babel-loader": "8.1.0",
"conventional-changelog-cli": "2.1.1",
"conventional-changelog-core": "4.2.1",
"conventional-changelog-emojis": "3.1.0",
"core-js": "^3.22.8",
"eslint": "7.32.0",
"eslint-config-airbnb-typescript": "12.0.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsx-a11y": "6.4.1",
"eslint-plugin-react": "7.21.5",
"eslint-plugin-react-hooks": "4.3.0",
"husky": "4.3.5",
"jest-localstorage-mock": "2.4.3",
"jest-styled-components": "^7.0.8",
"jest-transform-stub": "2.0.0",
"prettier": "2.1.2",
"prettier-plugin-organize-imports": "^3.0.0",
"pretty-quick": "3.1.0",
"process": "0.11.10",
"react-is": "17.0.1",
"react-test-renderer": "^17.0.2",
"release-it": "14.11.5",
"svg-jest": "1.0.1"
},
"resolutions": {
"react-error-overlay": "6.0.9",
"world_countries_lists": "2.3.0",
"#types/react": "17.0.2",
"#types/react-dom": "17.0.2"
}
}

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js in ReactJS

I have been through all the similar questions on stackoverflow and also viewed several other source, yet I can't solve this issue for some reason.
On my React JS app I get the error messages as shown in the screenshot below. I am using react-app-rewired, but all the solutions with putting a config-override file in my rootfolder don't seem to work. In the other screenshot you can see all the files in the rootfolder.
I guess you will need more information to properly see what I am doing wrong. The config-overrides file is located in the node-modules/react-app-rewired folder.
This is the content of my config-overrides.js
const {paths} = require('./');
// load environment variables from .env files
// before overrides scripts are read
require(paths.scriptVersion + '/config/env');
const override = require(paths.configOverrides);
const webpack = typeof override === 'function'
? override
: override.webpack || ((config, env) => config);
if (override.devserver) {
console.log(
'Warning: `devserver` has been deprecated. Please use `devServer` instead as ' +
'`devserver` will not be used in the next major release.'
)
}
const devServer = override.devServer || override.devserver
|| ((configFunction) =>
(proxy, allowedHost) =>
configFunction(proxy, allowedHost));
const jest = override.jest || ((config) => config);
const pathsOverride = override.paths || ((paths, env) => paths);
// normalized overrides functions
module.exports = {
webpack,
devServer,
jest,
paths: pathsOverride
};
this is the content of my package.json
{
"name": "fuse-react-app",
"version": "8.2.1",
"private": true,
"dependencies": {
"#date-io/date-fns-jalali": "2.15.0",
"#emotion/cache": "11.9.3",
"#emotion/react": "11.9.3",
"#emotion/styled": "11.9.3",
"#fullcalendar/daygrid": "5.11.2",
"#fullcalendar/interaction": "5.11.2",
"#fullcalendar/react": "5.11.2",
"#fullcalendar/timegrid": "5.11.2",
"#googleapis/docs": "^1.0.1",
"#hookform/resolvers": "2.9.7",
"#mui/base": "5.0.0-alpha.93",
"#mui/icons-material": "5.8.4",
"#mui/lab": "5.0.0-alpha.95",
"#mui/material": "5.10.1",
"#mui/styles": "5.9.3",
"#mui/system": "5.10.1",
"#mui/utils": "5.9.3",
"#mui/x-data-grid": "5.15.2",
"#mui/x-date-pickers": "5.0.0-beta.6",
"#react-pdf/renderer": "^3.0.0",
"#reduxjs/toolkit": "1.8.5",
"apexcharts": "3.35.4",
"autosuggest-highlight": "3.3.4",
"axios": "0.27.2",
"axios-mock-adapter": "1.21.2",
"browserify-zlib": "^0.2.0",
"clsx": "1.2.1",
"core-js": "3.24.1",
"crypto-js": "4.1.1",
"date-fns": "2.29.1",
"date-fns-jalali": "2.21.3-1",
"draft-js": "0.11.7",
"draftjs-to-html": "0.9.1",
"firebase": "^9.10.0",
"framer-motion": "7.2.0",
"fs": "^0.0.1-security",
"google-map-react": "2.2.0",
"googleapis": "^108.0.0",
"history": "5.3.0",
"i18next": "21.9.1",
"jwt-decode": "3.1.2",
"keycode": "2.2.1",
"lodash": "4.17.21",
"marked": "4.0.18",
"material-ui-popup-state": "2.0.1",
"mobile-detect": "1.4.5",
"mobx": "^6.6.1",
"moment": "2.29.4",
"net": "^1.0.2",
"notistack": "1.0.6-next.3",
"os": "^0.1.2",
"perfect-scrollbar": "1.5.5",
"prismjs": "1.28.0",
"prop-types": "15.8.1",
"qs": "6.11.0",
"raw-loader": "4.0.2",
"react": "18.2.0",
"react-apexcharts": "1.4.0",
"react-autosuggest": "10.1.0",
"react-beautiful-dnd": "13.1.0",
"react-dom": "18.2.0",
"react-draft-wysiwyg": "1.15.0",
"react-draggable": "4.4.5",
"react-hook-form": "7.34.2",
"react-i18next": "11.18.4",
"react-imask": "6.4.2",
"react-masonry-css": "1.0.16",
"react-number-format": "4.9.3",
"react-pdf": "^5.7.2",
"react-popper": "2.3.0",
"react-redux": "8.0.2",
"react-router-dom": "6.3.0",
"react-spring": "8.0.27",
"react-swipeable": "7.0.0",
"react-swipeable-views": "0.14.0",
"react-swipeable-views-utils": "0.14.0",
"react-table": "7.8.0",
"react-transition-group": "4.4.5",
"react-virtualized": "9.22.3",
"react-window": "1.8.7",
"redoc": "2.0.0-rc.76",
"redux-logger": "4.0.0",
"stream": "^0.0.2",
"styled-components": "5.3.5",
"stylis": "4.1.1",
"stylis-plugin-rtl": "2.1.1",
"tls": "^0.0.1",
"tools": "^0.0.0",
"web-vitals": "2.1.4",
"yup": "0.32.11",
"zlib": "^1.0.5"
},
"peerDependencies": {
"autoprefixer": "10.4.7",
"postcss": "8.4.13",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"resolutions": {
"react": "18.2.0",
"react-dom": "18.2.0",
"babel-loader": "8.1.0"
},
"devDependencies": {
"#babel/core": "7.17.10",
"#babel/eslint-parser": "7.17.0",
"#babel/node": "7.17.10",
"#babel/preset-env": "7.17.10",
"#babel/preset-react": "7.16.7",
"#tailwindcss/aspect-ratio": "^0.4.0",
"#tailwindcss/line-clamp": "^0.4.0",
"#tailwindcss/typography": "^0.5.4",
"#typescript-eslint/eslint-plugin": "^4.33.0",
"#typescript-eslint/parser": "^4.33.0",
"assert": "^2.0.0",
"autoprefixer": "9.8.8",
"buffer": "^6.0.3",
"cross-env": "7.0.3",
"crypto-browserify": "^3.12.0",
"eslint": "7.32.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.10.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.26.1",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-unused-imports": "^1.1.5",
"https-browserify": "^1.0.0",
"immutable": "4.0.0",
"js-beautify": "1.14.0",
"os-browserify": "^0.3.0",
"postcss": "8.4.5",
"prettier": "^2.4.1",
"process": "^0.11.10",
"promise": "8.1.0",
"react-app-alias": "2.2.0",
"react-app-rewired": "^2.2.1",
"react-scripts": "5.0.1",
"source-map-explorer": "2.5.2",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"tailwindcss": "3.1.8",
"typescript": "4.6.4",
"url": "^0.11.0",
"util": "^0.12.5"
},
"scripts": {
"start": "react-app-rewired start",
"build": "cross-env GENERATE_SOURCEMAP=false react-app-rewired build",
"test": "react-app-rewired test --env=node",
"eject": "react-app-rewired eject",
"build-docs": "babel-node --presets #babel/preset-env src/app/main/documentation/material-ui-components/build.js",
"analyze": "react-app-rewired build && source-map-explorer 'build/static/js/*.js' --html analyze-result.html",
"lint": "eslint"
},
"engines": {
"node": ">=14.0.0",
"npm": ">=7.0.0"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 3 safari version"
]
}
}
The error message is telling you what you need to do. You must add the config override AND also manually install the missing package. Post the contents of your override file and package.json.

Is there a way to apply tailwind classes on react components without restart the server all the time to let each class work?

I have an issue where all the time I add a tailwind class in my react components in order to let the style associated to that class work I need to restart the server, otherwise the style is not applied, even though I can see in the console the class being associated to the component (but not the style itself, which it is not applied at all). The solution is restarting the server.
As soon as I restart the server, or delete the node module and re-install npm, then the style is applied. While, if I use a class I already used before, it works without restarting the project. I tried to upgrade tailwind but the problem still persists. Any clues?
This is my tailwindconfig file:
/* global require */
const defaultTheme = require('tailwindcss/defaultTheme');
module.exports = {
plugins: [require('#tailwindcss/forms')],
content: ['./src/**/*.{html,js,jsx,ts,tsx}'],
theme: {
extend: {
width: {
104: '26rem',
112: '28rem',
136: '34rem',
144: '36rem'
},
strokeWidth: {
1.5: '1.5'
},
maxWidth: {
104: '26rem',
112: '28rem'
},
colors: {
'green': {
400: '#89ADAA',
700: '#155C56'
},
'gray': {
500: '#B4B2B1',
700: '#AFADAC'
},
'black': {
500: '#1E1E1E'
},
'black-haze': {
100: '#F2F4F4',
300: '#DFE6E8',
500: '#CDD4DC'
},
'desert-storm': '#F4F2F0',
'spring-green': '#00FA91'
},
fontFamily: {
sans: ['Roboto', ...defaultTheme.fontFamily.sans]
},
transitionProperty: {
width: 'width'
}
}
}
};
this is my package.json:
{
"name": "customer_app_client",
"version": "0.1.0",
"private": true,
"dependencies": {
"#heroicons/react": "^1.0.6",
"#reduxjs/toolkit": "^1.7.2",
"#storybook/manager-webpack5": "^6.4.19",
"#types/react-redux": "^7.1.22",
"#types/redux-immutable-state-invariant": "^2.1.2",
"#types/webpack-env": "^1.16.3",
"dayjs": "^1.11.1",
"dotenv": "^16.0.0",
"msw": "^0.39.2",
"process": "^0.11.10",
"react": "^17.0.2",
"react-cookie": "^4.1.1",
"react-dom": "^17.0.2",
"react-phone-input-2": "^2.15.0",
"react-redux": "^7.2.6",
"react-router-dom": "6.2.1",
"react-table": "^7.7.0",
"react-toastify": "7.0.4",
"react-virtual": "^2.10.4",
"redux": "4.1.0",
"redux-immutable-state-invariant": "^2.1.0",
"typescript": "^4.5.5",
"web-vitals": "^2.1.4"
},
"scripts": {
"test": "jest",
"start:dev": "webpack serve --config webpack.config.dev.js --port 3006",
"build:dev": "webpack build --config webpack.config.dev.js",
"build:dev:all": "npm run build:dev && npm run build-storybook",
"clean:dev": "rm -rf node_modules && rm -rf dist",
"prettify": "npx prettier --write .",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook --output-dir ../public/storybook"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#babel/core": "^7.14.6",
"#babel/eslint-parser": "^7.17.0",
"#babel/preset-env": "^7.16.11",
"#babel/preset-react": "^7.16.7",
"#babel/preset-typescript": "^7.16.7",
"#storybook/addon-actions": "^6.4.19",
"#storybook/addon-docs": "^6.4.22",
"#storybook/addon-essentials": "^6.4.19",
"#storybook/addon-interactions": "^6.4.19",
"#storybook/addon-links": "^6.4.19",
"#storybook/addon-postcss": "^2.0.0",
"#storybook/builder-webpack5": "^6.4.19",
"#storybook/react": "^6.4.19",
"#storybook/testing-library": "^0.0.9",
"#svgr/webpack": "^6.2.1",
"#tailwindcss/forms": "^0.5.2",
"#testing-library/jest-dom": "^5.16.2",
"#testing-library/react": "^12.1.3",
"#testing-library/user-event": "^13.5.0",
"#types/jest": "^27.4.0",
"#types/react": "^17.0.39",
"#types/react-dom": "^17.0.11",
"#types/react-router-dom": "^5.3.3",
"#types/react-table": "^7.7.11",
"#typescript-eslint/eslint-plugin": "^5.16.0",
"#typescript-eslint/parser": "^5.16.0",
"autoprefixer": "^10.4.7",
"babel-loader": "8.2.2",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "5.2.6",
"cssnano": "5.0.6",
"dotenv-webpack": "^7.1.0",
"eslint": "^8.11.0",
"eslint-config-prettier": "^8.4.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-webpack-plugin": "^3.1.1",
"fetch-mock": "9.11.0",
"file-loader": "^6.2.0",
"html-webpack-plugin": "5.3.2",
"http-server": "^14.1.0",
"jest": "27.5.1",
"jsdom": "^19.0.0",
"mdx-loader": "^3.0.2",
"npm-run-all": "4.1.5",
"postcss": "^8.4.14",
"postcss-import": "^14.0.2",
"postcss-loader": "6.1.1",
"prettier": "^2.5.1",
"react-docgen": "^5.4.0",
"react-docgen-typescript": "^2.2.2",
"react-test-renderer": "17.0.2",
"style-loader": "3.0.0",
"tailwindcss": "^3.1.1",
"ts-loader": "^9.2.6",
"tsconfig-paths-webpack-plugin": "^3.5.2",
"webpack": "5.44.0",
"webpack-cli": "^4.9.0",
"webpack-dev-server": "4.7.4"
},
"engines": {
"node": "16.14.0"
},
"volta": {
"node": "16.14.0"
},
"msw": {
"workerDirectory": "public"
}
}

React-rails Cannot Find App Component in View

Finally after many steps of troubleshooting rails is rendering our NavBar component, but not the base App component where everything is imported. Wondering what I might need to consider if there's a gem version not working properly like uglifier? Out of my two react_components rendered it finds the NavBar fine.
index.html.erb:
<%= react_component('NavBar', { isUserAuthed: #is_user_authed }) %>
<%= react_component('App') %>
App.jsx:
import React from "react";
import 'fontsource-roboto';
import Home from "../components/Home";
class App extends React.Component {
render() {
return (
<>
<Home/>
</>
)
}
}
export default App;
application.js:
// app/javascript/packs/application.js
import Rails from "#rails/ujs"
import Turbolinks from "turbolinks"
import * as ActiveStorage from "#rails/activestorage"
import "channels"
var componentRequireContext = require.context("components", true);
var ReactRailsUJS = require("react_ujs");
ReactRailsUJS.useContext(componentRequireContext);
Rails.start()
Turbolinks.start()
ActiveStorage.start()
package.json:
{
"name": "my-webpack-project",
"private": true,
"dependencies": {
"#babel/plugin-proposal-class-properties": "^7.16.5",
"#babel/plugin-proposal-decorators": "^7.16.4",
"#babel/plugin-proposal-object-rest-spread": "^7.16.0",
"#babel/plugin-proposal-private-methods": "^7.16.0",
"#babel/plugin-proposal-private-property-in-object": "^7.16.0",
"#babel/plugin-syntax-dynamic-import": "^7.8.3",
"#babel/plugin-syntax-jsx": "^7.16.0",
"#babel/plugin-transform-destructuring": "^7.16.0",
"#babel/plugin-transform-regenerator": "^7.16.0",
"#babel/plugin-transform-runtime": "^7.16.4",
"#babel/preset-env": "^7.16.5",
"#date-io/date-fns": "^2.9.1",
"#date-io/moment": "^2.9.0",
"#jest/globals": "^26.3.0",
"#material-ui/core": "^4.11.0",
"#material-ui/icons": "^4.9.1",
"#material-ui/pickers": "^3.2.10",
"#rails/actioncable": "^6.1.4-1",
"#rails/activestorage": "^6.1.4-1",
"#rails/ujs": "^6.1.4-1",
"#rails/webpacker": "5.4.3",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"caniuse-lite": "^1.0.30001249",
"clsx": "^1.1.1",
"date-fns": "^2.16.1",
"fetch-mock": "^9.10.6",
"fontsource-roboto": "^3.0.3",
"html-webpack-plugin": "^4.5.2",
"isomorphic-fetch": "^2.2.1",
"jquery": "^3.5.0",
"leaflet": "^1.6.0",
"lodash": "^4.17.20",
"mapbox-gl": "^1.8.1",
"moment": "^2.27.0",
"node": "16",
"node-fetch": "^2.6.0",
"npm": "^6.14.7",
"popper.js": "^1.16.1",
"postcss-cssnext": "^3.1.0",
"prop-types": "^15.7.2",
"query-string": "^6.13.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-leaflet": "^2.6.1",
"react-password-strength": "^2.4.0",
"react-router-dom": "^5.1.2",
"react_ujs": "^2.6.1",
"recharts": "^2.0.9",
"sass": "^1.37.5",
"turbolinks": "^5.2.0",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3",
"uglify-js": "git://github.com/mishoo/UglifyJS2#harmony"
},
"devDependencies": {
"#babel/core": "^7.16.5",
"#webpack-cli/generators": "^2.4.1",
"autoprefixer": "^10.4.0",
"babel-loader": "^8.2.3",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"css-loader": "^5.2.7",
"jest": "^26.0.1",
"mini-css-extract-plugin": "^1.6.2",
"node-sass": "^7.0.0",
"post-loader": "^2.0.0",
"postcss": "^8.4.4",
"sass-loader": "^10.2.0",
"style-loader": "^2.0.0"
},
"version": "1.0.0",
"description": "My webpack project",
"scripts": {
"build": "webpack --mode=production --node-env=production",
"build:dev": "webpack --mode=development",
"build:prod": "webpack --mode=production --node-env=production",
"watch": "webpack --watch",
"serve": "webpack serve"
}
}
Do you have this in your config?
$ tail -n 12 webpack.config.js
})
],
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx|)$/,
exclude: /node_modules/,
use: ['babel-loader'],
}
]
}
}
https://github.com/reactjs/react-rails/blob/master/README.md#3-install-react-and-some-other-required-npm-packages
Update the Babel configuration in the package.json file:
"babel": {
"presets": [
- "./node_modules/shakapacker/package/babel/preset.js"
+ "./node_modules/shakapacker/package/babel/preset.js",
+ "#babel/preset-react"
]
},

React-intl - How to use a default Locale

This could be a very easy question, however I've not been able to find the answer for it anywhere.
How do I use a default locale with react-intl? Specifying a default message every time gets really messy. The way that I'm doing it at the moment doesn't seem to pick up the default message when the browser uses a locale that doesn't have a translation.
How I'm using it at the moment:
import React from 'react'
import { Route } from 'react-router-dom'
import { IntlProvider } from 'react-intl'
import { Provider } from 'react-redux'
import { MuiThemeProvider, CssBaseline } from '#material-ui/core'
// import translations
import da_translations from './translations/da.json'
import de_translations from './translations/de.json'
import el_translations from './translations/el.json'
import en_translations from './translations/en.json'
import defaultTheme from './themes/default'
import {
QueryParamProvider,
ExtendedStringifyOptions,
transformSearchStringJsonSafe,
} from 'use-query-params'
import configureStore from './redux/configure-store'
import { Routes } from './routes'
const store = configureStore()
const App = (): JSX.Element => {
const state = { locale: navigator.language.slice(0, 2) }
const messages: { [index: string]: any } = {
da: da_translations,
de: de_translations,
el: el_translations,
en: en_translations,
}
const queryStringifyOptions: ExtendedStringifyOptions = {
transformSearchString: transformSearchStringJsonSafe,
}
return (
<Provider store={store}>
<IntlProvider
defaultLocale={'en'}
locale={state.locale}
messages={messages[state.locale]}
>
<QueryParamProvider
ReactRouterRoute={Route}
stringifyOptions={queryStringifyOptions}
>
<MuiThemeProvider theme={defaultTheme}>
<CssBaseline />
<Routes />
</MuiThemeProvider>
</QueryParamProvider>
</IntlProvider>
</Provider>
)
}
export default App
edit:
package.json
{
"name": "myproj",
"version": "0.8.47",
"description": "frontend",
"private": false,
"main": "dist/index.js",
"dependencies": {
"#babel/register": "^7.12.1",
"#date-io/date-fns": "^1.3.13",
"#google-cloud/translate": "^6.0.3",
"#material-ui/core": "^4.11.1",
"#material-ui/icons": "4.2.1",
"#material-ui/lab": "^4.0.0-alpha.56",
"#material-ui/pickers": "^3.2.10",
"#types/axios": "^0.14.0",
"#types/history": "^4.7.3",
"#types/jest": "^24.9.1",
"#types/lodash": "^4.14.158",
"#types/node": "^12.12.7",
"#types/react": "^16.9.11",
"#types/react-dom": "^16.9.4",
"#types/react-html-parser": "^2.0.1",
"#types/react-intl": "^3.0.0",
"#types/react-redux": "^7.1.9",
"#types/react-resizable": "^1.7.2",
"#types/react-router-dom": "^5.1.2",
"#types/reselect": "^2.2.0",
"#types/seamless-immutable": "^7.1.13",
"accept-language": "^3.0.18",
"ag-grid-community": "^23.1.1",
"ag-grid-react": "^23.1.1",
"axios": "^0.19.1",
"chai": "^4.2.0",
"chartist": "0.10.1",
"classnames": "^2.2.6",
"clsx": "^1.1.0",
"date-fns": "^2.9.0",
"flexsearch": "^0.6.32",
"fs-extra": "^9.0.1",
"history": "4.9.0",
"immutable": "^4.0.0-rc.12",
"js-yaml": "^3.14.0",
"lodash": "^4.17.19",
"log4js": "^6.3.0",
"loglevel": "^1.6.6",
"minimist": "^1.2.5",
"perfect-scrollbar": "1.4.0",
"prop-types": "15.7.2",
"qs": "^6.9.4",
"query-string": "^6.13.1",
"react": "^16.12.0",
"react-chartist": "0.13.3",
"react-dom": "^16.12.0",
"react-google-maps": "9.4.5",
"react-html-parser": "^2.0.2",
"react-intl": "^3.11.0",
"react-redux": "^7.2.1",
"react-resizable": "^1.10.1",
"react-router-dom": "^5.1.2",
"react-scripts": "4.0.0",
"react-swipeable-views": "0.13.3",
"redux": "^4.0.5",
"redux-observable": "^1.2.0",
"reselect": "^4.0.0",
"seamless-immutable": "^7.1.4",
"use-query-params": "^1.1.6"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env jest-environment-jsdom-sixteen --verbose",
"eject": "react-scripts eject",
"install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm start",
"lint:check": "eslint . --ext=js,jsx; exit 0",
"lint:fix": "eslint . --ext=js,jsx --fix; exit 0",
"build-package-css": "cp src/assets/css/material-dashboard-react.css dist/material-dashboard-react.css",
"build-package": "npm run build-package-css && babel src --out-dir dist"
},
"keywords": [],
"author": "tb",
"license": "MIT",
"homepage": "./",
"optionalDependencies": {
"#types/googlemaps": "3.37.3",
"#types/markerclustererplus": "2.1.33",
"ajv": "6.10.2"
},
"devDependencies": {
"#testing-library/dom": "^7.24.2",
"#testing-library/jest-dom": "^5.11.1",
"#testing-library/react": "^10.4.7",
"#testing-library/user-event": "^12.1.4",
"#types/chai": "^4.2.13",
"#types/classnames": "^2.2.10",
"#types/enzyme": "^3.10.5",
"#types/enzyme-adapter-react-16": "^1.0.6",
"#types/gulp": "^4.0.7",
"#types/jsdom": "^16.2.2",
"#typescript-eslint/eslint-plugin": "^4.7.0",
"#typescript-eslint/parser": "^4.7.0",
"axios-mock-adapter": "^1.18.2",
"cross-env": "^5.1.4",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint-config-prettier": "6.0.0",
"eslint-plugin-prettier": "3.1.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"gulp": "^4.0.2",
"gulp-append-prepend": "1.0.8",
"gulp-filter": "^6.0.0",
"gulp-prettier": "^3.0.0",
"husky": "^4.3.0",
"jest-environment-jsdom-sixteen": "^1.0.3",
"jsdom": "^16.2.2",
"prettier": "^2.1.2",
"pretty-quick": "^3.1.0",
"react-intl-translations-manager": "^5.0.3",
"ts-node": "^9.0.0",
"typescript": "^3.9.7"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": []
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
},
"jest": {
"transformIgnorePatterns": [
"node_modules/(?!(#ui5|lit-html)).*\\.js$"
]
}
}

Resources