React App Keep Reloading until it get crashed - reactjs

I am new to react js, I created a react app, and whenever I try to open the app it continuously reloads. can anyone help me in this? i tried but unable to find out any perfect solution.
Any solution?
package.json
{
"name": "sf",
"author": "KKK Team",
"version": "0.0.1",
"private": true,
"homepage": "/sfrs",
"scripts": {
"start": "env-cmd -f .env.development react-scripts start",
"build:development": "env-cmd -f .env.development react-scripts build",
"build:nonprod": "env-cmd -f .env.nonprod react-scripts build",
"build:production": "env-cmd -f .env.production react-scripts build",
"build": "react-scripts build",
"test": "jest --verbose",
"test:dev": "jest",
"test:watch": "jest --silent --watchAll",
"test:coverage": "jest --silent --coverage",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"dependencies": {
"#date-io/date-fns": "^1.3.13",
"#emotion/react": "^11.7.1",
"#emotion/styled": "^11.6.0",
"#material-table/core": "^0.2.20",
"#mui/icons-material": "^5.3.1",
"#mui/lab": "^5.0.0-alpha.66",
"#mui/material": "^5.3.1",
"#mui/styles": "^5.3.0",
"axios": "^0.25.0",
"buffer": "^6.0.3",
"clsx": "^1.1.1",
"crypto-browserify": "^3.12.0",
"env-cmd": "^10.1.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"msal": "^1.4.16",
"prop-types": "^15.8.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-perfect-scrollbar": "^1.5.8",
"react-redux": "^7.2.6",
"react-router": "^6.2.1",
"react-router-dom": "^6.2.1",
"recompose": "^0.30.0",
"redux": "^4.1.2",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.4.1",
"stream-browserify": "^3.0.0",
"sweetalert2": "^11.4.8",
"sweetalert2-react-content": "^4.2.0",
"util": "^0.12.4",
"validator": "^13.7.0",
"web-vitals": "^2.1.4"
},
"devDependencies": {
"#testing-library/jest-dom": "^5.16.1",
"#testing-library/react": "^12.1.2",
"#testing-library/user-event": "^13.5.0",
"eslint": "^7.11.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^4.0.8",
"husky": "^4.2.3",
"jest-canvas-mock": "^2.3.1",
"lint-staged": "^10.0.8",
"prettier": "^1.19.1",
"react-error-overlay": "^6.0.9",
"react-scripts": "4.0.3"
},
"jest": {
"setupFiles": [
"jest-canvas-mock"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm run test"
}
},
"lint-staged": {
"src/**/*.{js,jsx,json,css}": [
"prettier --write",
"eslint --fix"
]
},
"babel": {
"presets": [
"#babel/preset-react",
[
"#babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
],
"plugins": [
[
"#babel/plugin-proposal-class-properties",
{
"loose": true
}
]
]
},
"resolutions": {
"react-error-overlay": "6.0.9"
}
}
I am using MUI 5. I have tried with upgrading and degrading the node version but unable to solve the issue.
app.jsx
import 'react-perfect-scrollbar/dist/css/styles.css';
import React, { useEffect } from 'react';
import { useRoutes } from 'react-router-dom';
import _ from 'lodash';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { ThemeProvider } from '#mui/material';
import AuthProvider from './components/auth_provider';
import GlobalStyles from './components/globalstyles';
import theme from './theme/theme';
import AuthenticationProgressLoader from './components/authentication_progress_loader';
import UnAuthorized from './components/unauthorized';
import routeManager from './lib/route.manager';
import Alerts from './components/c_alert';
import PageProgress from './components/c_page_progress';
import PermissionManager from './lib/permission.manager';
const App = props => {
const {
userAccount,
userPermissions,
graphProfile,
routesConfig,
alerts,
isPageLoader
} = props;
const routing = useRoutes(routesConfig || []);
useEffect(() => {
if (
!_.isEmpty(userPermissions) &&
PermissionManager.isUserMerchant() &&
_.isEmpty(routesConfig)
) {
routeManager.dispatchRoutes();
}
}, [routesConfig, userPermissions]);
return !userPermissions ||
(!_.isEmpty(userPermissions) && !PermissionManager.isUserMerchant()) ? (
<UnAuthorized />
) : (
<ThemeProvider theme={theme}>
<GlobalStyles />
{!_.isEmpty(alerts.message) && <Alerts />}
{isPageLoader && <PageProgress />}
{userAccount && graphProfile && !_.isEmpty(userPermissions) ? (
routing
) : (
<AuthenticationProgressLoader />
)}
</ThemeProvider>
);
};
App.propTypes = {
// eslint-disable-next-line react/forbid-prop-types
userAccount: PropTypes.object,
// eslint-disable-next-line react/forbid-prop-types
graphProfile: PropTypes.object,
// eslint-disable-next-line react/forbid-prop-types
userPermissions: PropTypes.object,
// eslint-disable-next-line react/forbid-prop-types
routesConfig: PropTypes.array,
// eslint-disable-next-line react/forbid-prop-types
alerts: PropTypes.object,
isPageLoader: PropTypes.bool
};
App.defaultProps = {
userAccount: {},
graphProfile: {},
userPermissions: {},
routesConfig: [],
alerts: {},
isPageLoader: false
};
function mapStatesToProps(state) {
const { userPermissions, graphProfile, userAccount } = state.auth;
const { routesConfig } = state.routes;
const { alerts } = state;
const { isPageLoader } = state.pageProgress;
return {
userPermissions,
graphProfile,
userAccount,
routesConfig,
alerts,
isPageLoader
};
}
const authApp = AuthProvider(App);
const connectedApp = connect(mapStatesToProps, null)(authApp);
// eslint-disable-next-line
export { connectedApp as App };

Related

Type '{ children: Element; }' has no properties in common with type 'IntrinsicAttributes'. TS2559

help this error
Type '{ children: Element; }' has no properties in common with type 'IntrinsicAttributes'. TS2559
Code - react app
import { datadogRum } from "#datadog/browser-rum";
import DateFnsUtils from "#date-io/date-fns";
import { CssBaseline, IconButton, ThemeProvider } from "#material-ui/core";
import CloseIcon from "#material-ui/icons/Close";
import { MuiPickersUtilsProvider } from "#material-ui/pickers";
import { HomeUserContextProvider } from "./context/HomeUserContext";
import ptBRLocale from "date-fns/locale/pt-BR";
import { ProviderContext, SnackbarProvider } from "notistack";
import React, { useRef } from "react";
import Routes from "./components/Routes";
import Theme from "./components/Theme";
import { IoCProvider } from "./context/IoCContext/IoCContext";
import { UserProvider } from "./context/UserContext";
import "./index.css";
import { AuthProvider } from "#context/auth/AuthContext";
interface Props {
keyCloakUser: {
sub: string;
firstName: string;
email: string;
fullName: string;
listCNPJ?: {
CNPJ: string;
companyName: string;
}[];
roles: string[];
isAdmin?: boolean;
token: string;
};
}
const App: React.FC<Props> = ({ keyCloakUser }) => {
datadogRum.init({
applicationId: "57b83764-2666-4bea-9b6f-e9f4e02f67c2",
clientToken: "pub633ca71e0f8ee8add1c3305bfb02277c",
site: "datadoghq.com",
service: "portal-do-cliente-atem",
env: "prod",
// Specify a version number to identify the deployed version of your application in Datadog
// version: '1.0.0',
sampleRate: 100,
sessionReplaySampleRate: 20,
trackInteractions: true,
trackResources: true,
trackLongTasks: true,
defaultPrivacyLevel: "mask-user-input",
});
datadogRum.startSessionReplayRecording();
const notistackRef = useRef<ProviderContext>();
const onClickDismiss = (key: string | number) => () => {
notistackRef &&
notistackRef.current &&
notistackRef.current.closeSnackbar(key);
};
return (
<IoCProvider>
<MuiPickersUtilsProvider utils={DateFnsUtils} locale={ptBRLocale}>
<ThemeProvider theme={Theme}>
<UserProvider
userData={{
userID: keyCloakUser.sub,
firstName: keyCloakUser.firstName,
email: keyCloakUser.email,
fullName: keyCloakUser.fullName,
roles: keyCloakUser.roles,
listCNPJ: keyCloakUser.listCNPJ ? keyCloakUser.listCNPJ : [],
isAdmin: Boolean(keyCloakUser.isAdmin),
token: keyCloakUser.token,
}}
>
<SnackbarProvider
autoHideDuration={5000}
maxSnack={3}
preventDuplicate
//#ts-ignore
ref={notistackRef}
action={(key) => (
<IconButton size="small" onClick={onClickDismiss(key)}>
<CloseIcon htmlColor="#fff" />
</IconButton>
)}
>
<CssBaseline />
<AuthProvider>
<HomeUserContextProvider>
<Routes />
</HomeUserContextProvider>
</AuthProvider>
</SnackbarProvider>
</UserProvider>
</ThemeProvider>
</MuiPickersUtilsProvider>
</IoCProvider>
);
};
export default App;
Code below - component IOC
import React, { createContext, useContext } from "react";
import { appIocContainer } from "../../ioc";
import { IIoCContext } from "./IIoCContext";
const IoCContext = createContext<IIoCContext>({} as IIoCContext);
const IoCProvider: React.FC = ({ children }) => {
return (
<IoCContext.Provider value={{ serviceContainer: appIocContainer }}>
{children}
</IoCContext.Provider>
);
};
const useIoCContext = (): IIoCContext => {
const context = useContext(IoCContext);
if (!Object.keys(context).length) {
throw new Error(
"useIoCContext deve ser utilizado dentro de um IoCProvider"
);
}
return context;
};
export { useIoCContext, IoCProvider };
package.json
{
"name": "portal-cliente-atem",
"version": "0.1.101",
"private": true,
"dependencies": {
"#datadog/browser-rum": "^4.23.3",
"#date-io/date-fns": "1.x",
"#fontsource/montserrat": "^4.5.13",
"#material-ui/core": "^4.11.0",
"#material-ui/icons": "^4.9.1",
"#material-ui/lab": "^4.0.0-alpha.57",
"#material-ui/pickers": "^3.2.10",
"#material-ui/styles": "^4.11.5",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"#types/babel__core": "^7.1.20",
"#types/jest": "^24.0.0",
"#types/node": "^12.0.0",
"#types/react": "^18.0.0",
"#types/react-dom": "^18.0.0",
"#types/react-slick": "^0.23.8",
"#typescript-eslint/eslint-plugin": "^5.49.0",
"#typescript-eslint/parser": "^5.49.0",
"apexcharts": "^3.35.2",
"axios": "^0.21.0",
"clsx": "^1.1.1",
"date-fns": "^2.16.1",
"formik": "^2.1.5",
"framer-motion": "^8.4.2",
"html-react-parser": "^0.14.1",
"inversify": "^5.0.1",
"jwt-decode": "^3.1.2",
"keycloak-js": "^11.0.2",
"lodash.groupby": "^4.6.0",
"lodash.throttle": "^4.1.1",
"material-ui": "^1.0.0-beta.47",
"moment-timezone": "^0.5.32",
"notistack": "^1.0.0",
"pdfmake": "^0.1.68",
"react": "^16.13.1",
"react-apexcharts": "^1.4.0",
"react-dom": "^16.13.1",
"react-json-view": "^1.19.1",
"react-material-ui-carousel": "^2.1.1",
"react-quill": "^1.3.5",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"react-slick": "^0.29.0",
"reflect-metadata": "^0.1.13",
"rsuite": "^5.25.0",
"slick-carousel": "^1.8.1",
"typescript": "^4.0.0",
"uuid": "^8.3.2",
"yup": "^0.29.3"
},
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject",
"start:prod": "REACT_APP_ENVIRONMENT='production' react-app-rewired start",
"start:homologation": "REACT_APP_ENVIRONMENT='homologation' react-app-rewired start",
"build:homologation": "REACT_APP_ENVIRONMENT='homologation' react-app-rewired build"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#types/lodash.groupby": "^4.6.6",
"#types/lodash.throttle": "^4.1.6",
"#types/pdfmake": "^0.1.16",
"#types/react-router-dom": "^5.1.5",
"#types/uuid": "^8.3.0",
"#types/yup": "^0.29.7",
"eslint-config-react-app": "^7.0.1",
"husky": "^4.3.0",
"prettier": "2.1.2",
"pretty-quick": "^3.1.0",
"react-app-rewired": "^2.1.7"
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
},
"resolutions": {
"#types/react": "18.0.0",
"#types/react-dom": "18.0.0"
}
}

Fail to load storybook everytime

Failed to load storybook, everytime,I run npm run storybook
I have ever tried to clear the npm-cache as well, it didn't worked out.
I am using latest version of storybook - v6.5.4
Error:
triggerUncaughtException(err, true /* fromPromise */);
^
[Error: EBUSY: resource busy or locked, open 'C:\Users\soham.nandi\Desktop\analytics-storybook\node_modules.cache\storybook\dev-server\325c8f456729b912b0d2134054eb7448-41ac79ddc5290d504ad69ef1fe8200a7'] {
errno: -4082,
code: 'EBUSY',
syscall: 'open',
path: 'C:\Users\soham.nandi\Desktop\analytics-storybook\node_modules\.cache\storybook\dev-server\325c8f456729b912b0d2134054eb7448-41ac79ddc5290d504ad69ef1fe8200a7'
main.js
module.exports = {
stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.#(js|jsx|ts|tsx)"],
addons: [
"#storybook/addon-links",
"#storybook/addon-essentials",
"#storybook/addon-interactions",
"#storybook/preset-create-react-app",
"#storybook/addon-a11y",
],
framework: "#storybook/react",
core: {
builder: "#storybook/builder-webpack5",
},
features: {
storyStoreV7: true,
},
};
main.js
import { Suspense } from "react";
import { initReactI18next } from "react-i18next";
import i18n from "i18next";
import HttpApi from "i18next-http-backend";
import { LANGUAGES, TIMEZONES } from "../src/constants";
import "../node_modules/bootstrap/scss/bootstrap.scss";
import "../src/styles/index.scss";
i18n
.use(initReactI18next)
.use(HttpApi)
.init({
supportedLngs: LANGUAGES,
fallbackLng: "en-US",
lng: "en-US",
backend: {
loadPath: "/assets/locals/{{lng}}/translation.json",
},
react: { useSuspence: false },
});
export const globalTypes = {
locale: {
name: "Change Language",
description: "Change Language Support for the application",
defaultValue: "en-US",
toolbar: {
icon: "lightning",
items: LANGUAGES,
showName: true,
},
},
timezone: {
name: "Change Timezone",
description: "Change Timezone Support for the application",
defaultValue: "Asia/Kolkata",
toolbar: {
icon: "time",
items: TIMEZONES,
showName: true,
},
},
};
export const decorators = [
(Story, context) => {
i18n.changeLanguage(context.globals.locale);
return (
<div style={{ margin: "3em" }}>
<Suspense fallback={<div>Loading...</div>}>
<Story />
</Suspense>
</div>
);
},
];
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
options: {
storySort: (a, b) =>
a.title === b.title
? 0
: a.id.localeCompare(b.id, undefined, { numeric: true }),
},
};
package.js
{
"name": "analytics-storybook",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"bootstrap": "^5.1.3",
"date-fns": "^2.28.0",
"date-fns-tz": "^1.3.4",
"i18next": "^21.8.2",
"i18next-http-backend": "^1.4.0",
"lodash": "^4.17.21",
"react": "^17.0.2",
"react-bootstrap": "^2.4.0",
"react-datepicker": "^4.7.0",
"react-dom": "^17.0.2",
"react-i18next": "^11.16.9",
"react-scripts": "^5.0.1",
"react-select": "^5.3.2",
"react-table": "^7.8.0",
"react-table-sticky": "^1.1.3",
"sass": "^1.51.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"eject": "react-scripts eject",
"lint": "eslint .",
"lint:fix": "eslint --fix",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#storybook/addon-a11y": "^6.5.4",
"#storybook/addon-actions": "^6.5.4",
"#storybook/addon-essentials": "^6.5.4",
"#storybook/addon-interactions": "^6.5.4",
"#storybook/addon-links": "^6.5.4",
"#storybook/builder-webpack5": "^6.5.4",
"#storybook/manager-webpack5": "^6.5.4",
"#storybook/node-logger": "^6.5.4",
"#storybook/preset-create-react-app": "^4.1.1",
"#storybook/react": "^6.5.4",
"#storybook/testing-library": "^0.0.11",
"babel-plugin-named-exports-order": "^0.0.2",
"eslint": "^7.32.0",
"eslint-plugin-react": "^7.30.0",
"eslint-plugin-storybook": "^0.5.12",
"identity-obj-proxy": "^3.0.0",
"prop-types": "^15.8.1",
"webpack": "^5.72.1"
}
}
npm version: v8.10.0
node version: v16.15.0
Try changing your node version to LTS.
I got the solution, it was due to some Hp driver. I uninstalled it, it started working
Driver name: HP Wolf Security
https://support.aspnetzero.com/QA/Questions/11057/Error-EBUSY-resource-busy-or-locked-when-running-npm-run-create-bundles

How to figure out the types of JavaScript libraries for TypeScript with example?

I have the following code I am trying to port to TypeScript:
import { styled } from '#mui/material/styles';
export const Logo = styled((props) => {
const { variant, ...other } = props;
I am getting the error:
TS2339: Property 'variant' does not exist on type '{}'.
I look at the styled function first to try to figure out the type and see that it is taking a Component generic.
In WebStorm, go to declaration on styled() function brings me here which seems odd as I do not see that function name here...
<C extends React.JSXElementConstructor<React.ComponentProps<C>>>(
component: C,
options?: StyledOptions<PropsOf<C> & MUIStyledCommonProps> & MuiStyledOptions,
): CreateStyledComponent<PropsOf<C> & MUIStyledCommonProps, {}, {}, Theme>;
Go to declaration on styled from the import brings me here:
declare const styled: CreateMUIStyled<Theme>;
I try to modify my code to
import {CreateMUIStyled, styled, Theme} from '#mui/material/styles';
import PropTypes from 'prop-types';
export const Logo = styled((props: CreateMUIStyled<Theme>) => {
const { variant, ...other } = props;
resulting in error:
TS2339: Property 'variant' does not exist on type 'CreateMUIStyled '
How do I debug this myself on a case by case basis?. Part of that is my perhaps trudging through and getting used to each error.
Then on this specific issue, what is the type on props so there is a variant to break off?
The full JavaScript file (not sure if Logo.defaultProps at bottom helps as that doesn't compile either) ->
import {styled} from '#mui/material/styles';
import PropTypes from 'prop-types';
export const Logo = styled((props) => {
const { variant, ...other } = props;
const color = variant === 'light' ? '#C1C4D6' : '#5048E5';
return (
<svg
width="42"
height="42"
viewBox="0 0 42 42"
xmlns="http://www.w3.org/2000/svg"
{...other}>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M22.6744 4.50247L31.9038 9.66459C32.117 9.78381 32.2944 9.95738 32.4178 10.1674C32.5413 10.3775 32.6064 10.6164 32.6064 10.8597C32.6064 11.1031 32.5413 11.342 32.4178 11.5521C32.2944 11.7621 32.117 11.9357 31.9038 12.0549L22.6745 17.2172C22.0854 17.5467 21.4212 17.7198 20.7456 17.7198C20.0698 17.7198 19.4056 17.5467 18.8166 17.2172L9.5873 12.0549C9.37415 11.9357 9.1967 11.7621 9.0732 11.5521C8.94971 11.342 8.8846 11.1031 8.8846 10.8597C8.8846 10.6164 8.94971 10.3775 9.0732 10.1674C9.1967 9.95738 9.37415 9.78381 9.5873 9.66459L18.8166 4.50247C19.4056 4.17301 20.0698 4 20.7456 4C21.4212 4 22.0854 4.17301 22.6744 4.50247Z"
fill={color}
/>
<path
opacity="0.7"
d="M22.6244 9.34853L35.8422 16.7415C36.0554 16.8607 36.2328 17.0343 36.3563 17.2443C36.4798 17.4544 36.5449 17.6933 36.5449 17.9366C36.5449 18.18 36.4798 18.419 36.3563 18.629C36.2328 18.8391 36.0554 19.0126 35.8422 19.1319L22.6244 26.5248C22.0355 26.8541 21.3712 27.0272 20.6956 27.0272C20.0199 27.0272 19.3557 26.8541 18.7667 26.5248L5.54893 19.1319C5.33578 19.0126 5.15833 18.8391 5.03483 18.629C4.91133 18.419 4.84623 18.18 4.84623 17.9366C4.84623 17.6933 4.91133 17.4544 5.03483 17.2443C5.15833 17.0343 5.33578 16.8607 5.54893 16.7415L18.7667 9.34853C19.3557 9.01916 20.0199 8.84615 20.6956 8.84615C21.3712 8.84615 22.0355 9.01916 22.6244 9.34853Z"
fill={color}
/>
<path
opacity="0.4"
d="M22.9257 14.1939L41.2984 24.4703C41.5113 24.5894 41.6884 24.7626 41.8117 24.9724C41.935 25.182 42 25.4206 42 25.6636C42 25.9065 41.935 26.1451 41.8117 26.3548C41.6884 26.5645 41.5113 26.7378 41.2984 26.8568L22.9257 37.1329C22.3377 37.4618 21.6745 37.6346 21 37.6346C20.3254 37.6346 19.6623 37.4618 19.0743 37.1329L0.701542 26.8568C0.488743 26.7378 0.311581 26.5645 0.188286 26.3548C0.0649948 26.1451 0 25.9065 0 25.6636C0 25.4206 0.0649948 25.182 0.188286 24.9724C0.311581 24.7626 0.488743 24.5894 0.701542 24.4703L19.0743 14.1939C19.6623 13.8651 20.3254 13.6923 21 13.6923C21.6745 13.6923 22.3377 13.8651 22.9257 14.1939Z"
fill={color}
/>
</svg>
);
})``;
Logo.defaultProps = {
variant: 'primary'
};
Logo.propTypes = {
variant: PropTypes.oneOf(['light', 'primary'])
};
My entire package.json is here:
{
"name": "reactpatterns-react",
"version": "0.1.0",
"private": true,
"engines": {
"node": ">=16.14.0 <= 16.14.0",
"npm": ">=8.3.1 <= 8.3.1"
},
"dependencies": {
"#auth0/auth0-spa-js": "1.19.4",
"#emotion/cache": "11.7.1",
"#emotion/react": "11.7.1",
"#emotion/server": "11.4.0",
"#emotion/styled": "11.6.0",
"#fullcalendar/common": "5.10.1",
"#fullcalendar/core": "5.10.1",
"#fullcalendar/daygrid": "5.10.1",
"#fullcalendar/interaction": "5.10.1",
"#fullcalendar/list": "5.10.1",
"#fullcalendar/react": "5.10.1",
"#fullcalendar/timegrid": "5.10.1",
"#fullcalendar/timeline": "5.10.1",
"#mui/icons-material": "5.3.1",
"#mui/lab": "5.0.0-alpha.67",
"#mui/material": "5.4.0",
"#mui/system": "5.4.0",
"#react-pdf/renderer": "2.1.1",
"#reduxjs/toolkit": "1.7.1",
"apexcharts": "3.33.0",
"aws-amplify": "4.3.14",
"date-fns": "2.28.0",
"draft-js": "0.11.7",
"firebase": "9.6.6",
"formik": "2.2.9",
"gray-matter": "4.0.3",
"i18next": "21.6.10",
"iconv-lite": "0.6.3",
"lodash.debounce": "4.0.8",
"next": "12.0.10",
"nprogress": "0.2.0",
"numeral": "2.0.6",
"prop-types": "15.8.1",
"react-apexcharts": "1.3.9",
"react-beautiful-dnd": "13.1.0",
"react-draft-wysiwyg": "1.14.7",
"react-dropzone": "11.2.4",
"react-hot-toast": "2.2.0",
"react-i18next": "11.15.3",
"react-markdown": "8.0.0",
"react-quill": "2.0.0-beta.4",
"react-redux": "7.2.6",
"react-syntax-highlighter": "15.4.5",
"redux": "4.1.2",
"redux-devtools-extension": "2.13.9",
"redux-thunk": "2.4.1",
"simplebar": "5.3.6",
"simplebar-react": "2.3.6",
"stylis": "4.0.13",
"stylis-plugin-rtl": "2.1.1",
"yup": "0.32.11",
"#emotion/react": "11.8.1",
"#emotion/styled": "11.8.1",
"#mui/material": "5.4.4",
"#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/node": "16.11.25",
"#types/react": "17.0.39",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-router-dom": "6.2.1",
"react-scripts": "5.0.0",
"ts-generic-collections-linq": "1.0.7",
"typescript": "4.5.5",
"web-vitals": "2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build:old": "react-scripts build",
"build:prod": "BUILD_PATH='../reactpatterns/src/dist/react' dotenv -e .env.production react-scripts build",
"build:dev": "BUILD_PATH='../reactpatterns/src/dist/react' dotenv -e .env.development react-scripts build",
"build": "echo \"Please use build:dev or build:prod \" && exit 1",
"test": "react-scripts test",
"eject": "react-scripts eject",
"watch": "webpack --watch --progress"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#svgr/webpack": "6.2.1",
"eslint": "8.8.0",
"eslint-config-next": "12.0.10",
"next-transpile-modules": "9.0.0",
"#babel/core": "7.17.5",
"#babel/preset-env": "7.16.11",
"#babel/preset-react": "7.16.7",
"#types/react-dom": "17.0.11",
"babel-loader": "8.2.3",
"css-loader": "6.6.0",
"dotenv-cli": "5.0.0",
"html-webpack-plugin": "5.5.0",
"ts-loader": "9.2.6",
"typescript": "4.5.5",
"webpack": "5.69.1",
"webpack-cli": "4.9.2",
"webpack-dev-server": "4.7.4"
}
}
I looked at the docs and you need to pass a React Component as the first argument of the styled function. In your example you are passing a function component without defining the type of the "props". But the type of "props" default to {} as you can see here. That's why you are getting the error.
So you simply need to provide the type of your props like so:
export const Logo = styled((props: PropTypeOfYourFunctionalComponent) => {
// code of your functional component
});
Where PropTypeOfYourFunctionalComponent is the type of your functional component's React props.
In order to type a value called field in my styled function i do this:
import type { RichTextField } from '#prismicio/types';
import { asText } from '#prismicio/helpers';
import { PrismicRichText } from '#prismicio/react';
import { styled, Typography, TypographyTypeMap } from '#mui/material';
type ParagraphStyledProps = TypographyTypeMap<{ field: RichTextField }>['props']
const ParagraphStyled = styled(({ field, ...props }: ParagraphStyledProps) => (
<Typography key={asText(field)} {...props}>
<PrismicRichText field={field} />
</Typography>
))(({ theme }) => ({
// ...some style
}));

WebSocket connection to 'wss://localhost:3000/sockjs-node' failed:

I am working in a react application (Below Package.json)
{
"name": "seed",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:8080",
"dependencies": {
"#ckeditor/ckeditor5-adapter-ckfinder": "23.1.0",
"#ckeditor/ckeditor5-alignment": "23.1.0",
"#ckeditor/ckeditor5-autoformat": "23.1.0",
"#ckeditor/ckeditor5-basic-styles": "23.1.0",
"#ckeditor/ckeditor5-block-quote": "23.1.0",
"#ckeditor/ckeditor5-build-classic": "23.1.0",
"#ckeditor/ckeditor5-ckfinder": "23.1.0",
"#ckeditor/ckeditor5-dev-utils": "^23.5.1",
"#ckeditor/ckeditor5-dev-webpack-plugin": "^23.5.1",
"#ckeditor/ckeditor5-easy-image": "23.1.0",
"#ckeditor/ckeditor5-editor-classic": "23.1.0",
"#ckeditor/ckeditor5-editor-decoupled": "23.1.0",
"#ckeditor/ckeditor5-font": "23.1.0",
"#ckeditor/ckeditor5-heading": "23.1.0",
"#ckeditor/ckeditor5-highlight": "23.1.0",
"#ckeditor/ckeditor5-image": "23.1.0",
"#ckeditor/ckeditor5-link": "23.1.0",
"#ckeditor/ckeditor5-list": "23.1.0",
"#ckeditor/ckeditor5-media-embed": "23.1.0",
"#ckeditor/ckeditor5-paste-from-office": "23.1.0",
"#ckeditor/ckeditor5-react": "3.0.0",
"#ckeditor/ckeditor5-real-time-collaboration": "23.1.0",
"#ckeditor/ckeditor5-remove-format": "23.1.0",
"#ckeditor/ckeditor5-table": "23.1.0",
"#ckeditor/ckeditor5-theme-lark": "23.1.0",
"#date-io/date-fns": "1.3.13",
"#material-ui/core": "4.9.10",
"#material-ui/icons": "^4.9.1",
"#material-ui/lab": "^4.0.0-alpha.56",
"#material-ui/pickers": "^3.2.10",
"#types/pdfjs-dist": "^2.1.5",
"aws-amplify": "^3.0.22",
"babel-polyfill": "6.26.0",
"connected-react-router": "^6.3.2",
"date-fns": "^2.14.0",
"env-cmd": "8.0.2",
"formik": "2.1.5",
"history": "4.7.2",
"juice": "^7.0.0",
"lodash": "^4.17.11",
"pdf-viewer-reactjs": "^2.0.7",
"pdfjs-dist": "2.4.456",
"raw-loader": "^4.0.1",
"react": "^16.8.3",
"react-dom": "^16.8.3",
"react-hot-toast": "^1.0.2",
"react-intl": "2.7.2",
"react-redux": "^6.0.1",
"react-router": "4.3.1",
"react-router-dom": "4.3.1",
"react-scripts": "^2.1.5",
"redux": "4.0.1",
"redux-persist": "5.10.0",
"redux-persist-transform-filter": "^0.0.20",
"redux-saga": "^1.0.2",
"styled-components": "4.1.1",
"superagent": "4.0.0",
"typesafe-actions": "^3.0.0",
"yup": "^0.28.3"
},
"scripts": {
"start": "HTTPS=true REACT_APP_ENV=local react-app-rewired start",
"start:windows": "set HTTPS=true&&set REACT_APP_ENV=local&&react-app-rewired start",
"build": "env-cmd .env.${REACT_APP_ENV} react-app-rewired build",
"build:staging": "REACT_APP_ENV=staging env-cmd .env.staging react-app-rewired build ",
"build:qa": "REACT_APP_ENV=qa env-cmd .env.qa react-app-rewired build ",
"build:qaint": "REACT_APP_ENV=qaint env-cmd .env.qaint react-app-rewired build ",
"build:euat": "REACT_APP_ENV=euat env-cmd .env.euat react-app-rewired build ",
"test": "react-app-rewired test --maxWorkers=4",
"test:ci": "react-app-rewired test --maxWorkers=4 --all --coverage",
"eject": "react-app-rewired eject",
"analyze": "env-cmd .env.${REACT_APP_ENV} react-app-rewired build --analyze-bundle",
"test:coverage": "npm run test -- --coverage",
"generate": "plop --plopfile scripts/generators/index.js",
"lint": "eslint 'src/**/*.{js,ts,tsx}'",
"lint:fix": "eslint 'src/**/*.{js,ts,tsx}' --fix",
"lint-style": "stylelint 'src/**/*.style.{ts,tsx}' 'src/**/style.{ts,tsx}'",
"cypress:run": "sudo docker-compose -f docker-compose-cypress.yml run e2e-chrome"
},
"browserslist": [
">0.2%",
"not dead",
"not ie < 11",
"not op_mini all"
],
"jest": {
"collectCoverageFrom": [
"src/**/*.js",
"!src/**/*.test.js",
"!src/**/actions.js",
"!src/**/index.js",
"!src/**/serviceWorker.js",
"!src/**/*.wrap.js",
"!src/index.js",
"!src/tempPolyfills.js",
"!src/setupTests.js",
"!src/redux/reducers.js",
"!src/redux/sagas.js",
"!src/redux/store.js",
"!src/**/mocks/**",
"!src/redux/reducers.ts",
"!src/redux/sagas.ts"
],
"coverageThreshold": {
"global": {
"statements": 0,
"branches": 0,
"functions": 0,
"lines": 0
}
},
"snapshotSerializers": [
"<rootDir>/node_modules/enzyme-to-json/serializer"
],
"setupFiles": [
"core-js"
]
},
"bundlesize": [
{
"path": "./build/static/js/*.js",
"maxSize": "200 kB"
}
],
"devDependencies": {
"#types/cheerio": "^0.22.10",
"#types/enzyme": "^3.1.15",
"#types/enzyme-react-intl": "^2.0.0",
"#types/history": "^4.7.2",
"#types/jest": "^23.3.12",
"#types/lodash": "^4.14.119",
"#types/node": "^10.12.18",
"#types/pdf-viewer-reactjs": "^2.0.0",
"#types/react": "^16.8.3",
"#types/react-dom": "^16.0.11",
"#types/react-intl": "^2.3.15",
"#types/react-redux": "^6.0.12",
"#types/react-router": "^4.4.3",
"#types/react-router-dom": "^4.3.1",
"#types/react-test-renderer": "^16.0.3",
"#types/redux-mock-store": "^1.0.2",
"#types/styled-components": "^4.1.5",
"#types/superagent": "^3.8.6",
"#types/webpack-env": "^1.13.6",
"#types/yup": "^0.26.34",
"#typescript-eslint/eslint-plugin": "^1.6.0",
"#typescript-eslint/parser": "^1.6.0",
"babel-plugin-styled-components": "1.8.0",
"enzyme": "3.7.0",
"enzyme-adapter-react-16": "1.15",
"enzyme-react-intl": "^2.0.6",
"enzyme-to-json": "3.3.4",
"eslint-config-prettier": "4.1.0",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-jest": "22.0.0",
"eslint-plugin-jsx-a11y": "6.1.2",
"eslint-plugin-mysticatea": "4.2.4",
"eslint-plugin-prefer-object-spread": "1.2.1",
"eslint-plugin-prettier": "3.0.0",
"eslint-plugin-react": "7.11.1",
"husky": "^4.2.5",
"mockdate": "^3.0.2",
"plop": "2.1.0",
"prettier": "1.15.1",
"react-app-rewire-webpack-bundle-analyzer": "1.0.1",
"react-app-rewired": "2.1.0",
"react-test-renderer": "16.10",
"redux-mock-store": "^1.5.4",
"redux-saga-test-plan": "^4.0.0-beta.2",
"stylelint": "^9.10.1",
"stylelint-config-prettier": "^4.0.0",
"stylelint-config-standard": "^18.2.0",
"stylelint-config-styled-components": "^0.1.1",
"stylelint-declaration-strict-value": "^1.1.2",
"stylelint-processor-styled-components": "^1.5.2",
"typescript": "^3.2.2",
"wait-on": "^3.2.0",
"webpack-manifest-plugin": "^2.0.4"
}
}
Below config-overrides.js
const { styles } = require( '#ckeditor/ckeditor5-dev-utils' );
module.exports = {
webpack: function override(config, env) {
const analyzeBundle = process.argv.indexOf('--analyze-bundle') !== -1;
if (analyzeBundle) {
const rewireWebpackBundleAnalyzer = require('react-app-rewire-webpack-bundle-analyzer');
config = rewireWebpackBundleAnalyzer(config, env, {
analyzerMode: 'static',
reportFilename: 'report.html',
});
}
// Fix strange issue with webpack build
// details here: https://stackoverflow.com/questions/60407393/create-react-app-production-build-runtime-error-cannot-read-property-call-of
// TODO: maybe update webpack to fix while keeping import optimization
config.optimization.sideEffects = false;
// Customize webpack config here
console.log("Loading Custom config for Webpack, rebuilding ckeditor");
const oneOfIndex = config.module.rules.findIndex(item => {
return item.hasOwnProperty("oneOf");
});
oneOf = config.module.rules[oneOfIndex].oneOf;
// Add the SVG and CSS loaders to the oneOf array
const additions = [
{
test: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
use: ["raw-loader"]
},
{
test: /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css$/,
use: [
{
loader: "style-loader",
},
{
loader: "postcss-loader",
options: styles.getPostCssConfig({
themeImporter: {
themePath: require.resolve("#ckeditor/ckeditor5-theme-lark")
},
minify: true
})
}
]
}
];
additions.forEach((item) => {
oneOf.push(item);
});
const cssRegex = /\.css$/;
const cssModuleRegex = /\.module\.css$/;
// Modify cssRegex
let loader;
loader = oneOf.find(item => {
if (item.test !== undefined)
return item.test.toString() === cssRegex.toString();
});
loader.exclude = [cssModuleRegex, /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css$/];
// Modify cssModuleRegex
loader = oneOf.find(item => {
if (item.test !== undefined)
return item.test.toString() === cssModuleRegex.toString();
});
loader.exclude = [/ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css$/];
// Modify file-loader
loader = oneOf.find(item => {
if (item.loader !== undefined)
return (
item.loader.toString() === require.resolve("file-loader").toString()
);
});
loader.exclude = [
/\.(js|mjs|jsx|ts|tsx)$/,
/\.html$/,
/\.json$/,
/ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
/ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css$/
];
config.module.rules[oneOfIndex].oneOf = oneOf;
return config;
},
devServer: function(configFunction) {
// Return the replacement function for create-react-app to use to generate the Webpack
// Development Server config. "configFunction" is the function that would normally have
// been used to generate the Webpack Development server config - you can use it to create
// a starting configuration to then modify instead of having to create a config from scratch.
return function(proxy, allowedHost) {
// Create the default config by calling configFunction with the proxy/allowedHost parameters
const defaultConfig = configFunction(proxy, allowedHost);
return {
...defaultConfig,
hot: true,
historyApiFallback: true,
// Allow mounting react apps from a page served by the backend.
headers: {
'Access-Control-Allow-Origin': 'http://localhost:8080',
},
};
};
},
};
I am trying to load another react application as a microfront end using :
I ve tested the imported microfront end in a simple react app (container) and everything went well
import React, {useCallback, useEffect} from 'react';
import {History} from 'history';
interface MicroFrontendProps {
history?: History;
name: string;
host: string | undefined;
}
const MicroFrontend: React.FC<MicroFrontendProps> = ({history, name, host,}) => {
const renderMicroFrontend = useCallback(() => {
(window as any)[`render${name}`](`${name}-container`, history);
}, [name, history]);
useEffect(() => {
const scriptId = `micro-frontend-script-${name}`;
if (document.getElementById(scriptId)) {
renderMicroFrontend();
} else {
fetch(`${host}/asset-manifest.json`)
.then(res => res.json())
.then(manifest => {
const promises = Object.keys(manifest.files)
.filter(key => key.endsWith('.js'))
.reduce((sum, key) => {
sum.push(
new Promise(resolve => {
const path = `${host}${manifest.files[key]}`;
const script = document.createElement('script');
if (key === 'main.js') {
script.id = scriptId;
}
script.onload = () => {
resolve();
};
script.crossOrigin = '';
script.src = path;
document.body.after(script);
}),
);
return sum;
}, [] as any);
Promise.allSettled(promises).then(() => {
renderMicroFrontend();
});
});
}
return () => {
(window as any)[`unmount${name}`](`${name}-container`);
};
}, [renderMicroFrontend, host, name]);
return <main id={`${name}-container`} />;
};
export default MicroFrontend;
When I am importing the app, when I go to a link which loads it I am getting this error (the imported app is rendred but server shuts down) :
webpackHotDevClient.js:60 WebSocket connection to 'wss://localhost:3000/sockjs-node' failed:
./node_modules/react-dev-utils/webpackHotDevClient.js # webpackHotDevClient.js:60
webpackHotDevClient.js:76 The development server has disconnected.
Refresh the page if necessary.
Do you have any idea about this error ?
Thanks

Storybook Viewport Addon: Custom Viewports Do Not Build (react)

I built an app using create-react-app. I create custom viewport types to add to my storybook. When I use yarn start everything builds fine and works. But when I build the app the viewports that I globally defined my preview.js file are not loading on the build. It is still the defaults. And for the life of me I can't figure out why. As far as I can tell I set it up the way the documentation explains.
This is my preview.js file
import { configure, addDecorator, addParameters } from '#storybook/react';
import { DocsPage, DocsContainer } from '#storybook/addon-docs/blocks';
import { withA11y } from '#storybook/addon-a11y';
import { GlobalStyle } from '../src/styles/global-styles';
const loaderFn = () => {
const allExports = [];
const styles = require.context('../src/styles', true, /\.stories\.(js|mdx)$/);
const req = require.context('../src/components', true, /\.stories\.(js|mdx)$/);
addDecorator(withA11y, GlobalStyle);
styles.keys().forEach(fname => allExports.push(styles(fname)));
req.keys().forEach(fname => allExports.push(req(fname)));
return allExports;
};
const customViewports = {
phoneSmall: {
name: 'Phone (320px min width)',
styles: {
width: '320px',
height: '667px',
},
},
tabletSmall: {
name: 'Tablet Small & Portrait (600px min width)',
styles: {
width: '600px',
height: '801px',
},
},
tabletLarge: {
name: 'Tablet Large & Landscape (960px min width)',
styles: {
width: '960px',
height: '768px',
},
},
desktop: {
name: 'Desktop (1200px min width)',
styles: {
width: '1200px',
height: '1024px',
},
},
};
configure(loaderFn, module);
addParameters({
docs: {
container: DocsContainer,
page: DocsPage,
},
viewport: { viewports: customViewports },
});
My main.js file
module.exports = {
stories: ['../src/**/*.stories.(js|mdx)'],
addons: [
'#storybook/preset-create-react-app',
'#storybook/addon-knobs/',
'#storybook/addon-actions',
'#storybook/addon-links',
'#storybook/addon-notes',
'#storybook/addon-storysource',
'#storybook/addon-a11y',
'#storybook/addon-docs',
'#storybook/addon-viewport',
]
}
Package.json
{
"name": "tamman-ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"#storybook/addon-a11y": "^5.3.17",
"#storybook/addon-actions": "^5.3.17",
"#storybook/addon-docs": "^5.3.17",
"#storybook/addon-knobs": "^5.3.17",
"#storybook/addon-links": "^5.3.17",
"#storybook/addon-notes": "^5.3.17",
"#storybook/addon-storyshots-puppeteer": "^5.3.17",
"#storybook/addon-storysource": "^5.3.17",
"#storybook/addon-viewport": "^5.3.17",
"#storybook/addons": "^5.3.17",
"#storybook/preset-create-react-app": "^2.1.0",
"#storybook/react": "^5.3.17",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"autoprefixer": "^9.7.5",
"camel-case": "^4.1.1",
"core-js": "^3.6.4",
"del": "^5.1.0",
"fs": "^0.0.1-security",
"node-sass": "^4.13.1",
"pascal-case": "^3.1.1",
"path": "^0.12.7",
"prop-types": "^15.7.2",
"puppeteer": "^2.1.1",
"react": "^16.12.0",
"react-dom": "^16.13.1",
"react-scripts": "^3.4.1",
"styled-components": "^5.0.1",
"xml2js": "^0.4.23"
},
"scripts": {
"start": "node ./src/components/atoms/Icon/utils/generate-icons.js && react-scripts start",
"build-page": "node ./src/components/atoms/Icon/utils/generate-icons.js && react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"storybook": "start-storybook -p 9009 -s public",
"build": "yarn build-page && build-storybook -o build/storybook"
},
"eslintConfig": {
"extends": "react-app"
},
"homepage": ".",
"browserslist": [
"since 2010"
],
"devDependencies": {
"babel-loader": "^8.1.0",
"react-is": "^16.12.0"
}
}
Seems to be working fine. Try registering the viewport add-on
// main.js
module.exports = {
...
addons: [
...
'#storybook/addon-viewport/register',
],
]
}
Like the docs suggest.

Resources