react-firebaseui StyledFirebaseAuth is not getting compiled - reactjs

I am using react-firebaseui for authentication, according to the documentation i have written the code
import React from "react";
import StyledFirebaseAuth from "react-firebaseui/StyledFirebaseAuth";
import firebase from "firebase";
const firebaseConfig = {
...
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// Configure FirebaseUI.
const uiConfig = {
// Popup signin flow rather than redirect flow.
signInFlow: "popup",
// Redirect to /signedIn after sign in is successful. Alternatively you can provide a callbacks.signInSuccess function.
// signInSuccessUrl: '/signedIn',
// We will display Google and Facebook as auth providers.
signInOptions: [firebase.auth.GoogleAuthProvider.PROVIDER_ID],
};
export const SignInWith = () => (
<>
<p>Login</p>
<StyledFirebaseAuth uiConfig={uiConfig} firebaseAuth={firebase.auth()} />
</>
);
but i keep getting this error
./node_modules/firebaseui/dist/esm.js
Attempted import error: 'app' is not exported from 'firebase/app' (imported as 'firebase').`.
I tried importing firebase using import firebase from 'firebase/app, but still the same error.
I tried commenting StyledFirebaseAuth import and tag and it is working, so I am sure the problem is with react-firebaseui.
This is my package.json
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"#material-ui/core": "^4.11.0",
"#material-ui/icons": "^4.9.1",
"#reduxjs/toolkit": "^1.4.0",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"#types/jest": "^24.9.1",
"#types/node": "^12.19.2",
"#types/react": "^16.9.54",
"#types/react-dom": "^16.9.9",
"#types/react-redux": "^7.1.9",
"axios": "^0.21.0",
"firebase": "^8.0.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-firebaseui": "^4.1.0",
"react-redux": "^7.2.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.0",
"typescript": "^3.8.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"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"
]
},
"devDependencies": {
"#types/react-router-dom": "^5.1.6",
"babel-plugin-import": "^1.13.1",
"customize-cra": "^1.0.0",
"react-app-rewired": "^2.1.6"
}
}
Thank you for any help.

Unfortunately, you've upgraded your "firebase" dependency to 8.0.0 but the "firebaseui" dependency doesn't support it yet. You will have to temporarily downgrade firebase to version 7.24.0 until firebaseui and react-firebaseui support the breaking changes in 8.0.0.

import firebase has changed with the version of 9.0.0, now there is compatibility available no need to downgrade, so you can use /compat folder in your imports,
import firebase from 'firebase/compat/app'

Related

index.tsx can't resolve App component in React app. .Tsx extensions are not recognised

I have just runned create-react-app, moved some code and components from another project and now I cannot figure out why I get an error that it fails to compile. App component exist exactly in the destination where it can't be found. I suppose there is some hint in console, but I cannot figure out what can be the issue.
import React from "react";
import ReactDOM from "react-dom/client";
import { App } from "./components/App/App";
import reportWebVitals from "./reportWebVitals";
const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
reportWebVitals();
Here I add a picture of App component to show You the location of app component.
Can You please suggest what is wrong here ?
Here You can see my package.json
{
"name": "flask_react",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:5000",
"dependencies": {
"#emotion/react": "^11.10.5",
"#emotion/styled": "^11.10.5",
"#mui/material": "^5.11.5",
"#mui/x-date-pickers": "^5.0.15",
"#testing-library/jest-dom": "^5.16.5",
"#testing-library/react": "^13.4.0",
"#testing-library/user-event": "^13.5.0",
"#types/react": "^18.0.27",
"formik": "^2.2.9",
"prettier": "^2.8.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.7.0",
"react-scripts": "5.0.1",
"ts-loader": "^9.4.2",
"typescript": "^4.9.4",
"web-vitals": "^2.1.4",
"yup": "^0.32.11"
},
"scripts": {
"start": "react-scripts start",
"start-backend": "cd backend && env/bin/flask run --no-debugger",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"eslint": "eslint ./src/**/*.{ts,tsx}"
},
"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": {
"#testing-library/jest-dom": "^5.16.5",
"#testing-library/react": "^13.4.0",
"#testing-library/user-event": "^13.5.0",
"#types/axios": "^0.14.0",
"#types/jest": "^27.5.2",
"#types/node": "^16.11.64",
"#types/react": "^18.0.21",
"#types/react-beautiful-dnd": "^13.1.2",
"#types/react-dom": "^18.0.6",
"#types/react-icons": "^3.0.0",
"#types/react-router": "^5.1.19",
"#types/react-router-dom": "^5.3.3",
"#typescript-eslint/eslint-plugin": "^5.39.0",
"#typescript-eslint/parser": "^5.39.0",
"env-cmd": "^10.1.0",
"eslint": "^8.24.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.8",
"eslint-plugin-react-hooks": "^4.6.0",
"prettier": "^2.7.1",
"typescript": "^4.8.4"
}
}
import { App } from "./components/App/App";
You are destructuring your App import with the curly brackets, which returns undefined. Instead it should be
import App from './components/App/App';
EDIT: as Yuriy pointed out in the comments, since this isn't a default export then what I said above won't fix the problem. I have thought of something else though, what if you specify the extension? Like so
import { App } from "./components/App/App.tsx";
according to the error most probably here you are not including the .tsx extenstion to your extensions array. update your webpack.config.js file as below :
module.exports = {
// ...
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"]
},
}

How to solve Github pages 404 problem when I use react router?

I try to deploy my typescript react app to Github pages, but every time when I access my URL, Github complains '404 there isn't a github pages site here.'
And I try to make my code simple, I just left the home page in my app, but it still complains.
If I don't use React router, it works. Why does it complain when I use react router?
My Code:
import Home from "./pages/Home" //rafce
import {
BrowserRouter,
Routes,
Route,
} from "react-router-dom";
const Router: React.FC = () => {
return <>
<BrowserRouter>
<Routes>
<Route path="/" ><Home /></Route>
</Routes>
</BrowserRouter>
</>
}
export default Router
My JSON:
{
"homepage": "http://lsk21007.github.io/ohno",
"name": "typescript-react",
"version": "0.1.0",
"private": true,
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^6.1.1",
"#fortawesome/free-regular-svg-icons": "^6.1.1",
"#fortawesome/free-solid-svg-icons": "^6.1.1",
"#fortawesome/react-fontawesome": "^0.1.18",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.2.0",
"#testing-library/user-event": "^13.5.0",
"#types/jest": "^27.5.1",
"#types/node": "^16.11.36",
"#types/react": "^18.0.9",
"#types/react-dom": "^18.0.4",
"bootstrap": "^5.2.0-beta1",
"react": "^18.1.0",
"react-bootstrap": "^2.4.0",
"react-dom": "^18.1.0",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"styled-components": "^5.3.5",
"typescript": "^4.6.4",
"web-vitals": "^2.1.4"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"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": {
"#types/styled-components": "^5.1.25",
"gh-pages": "^4.0.0"
}
}
Thanks for your help!!

JSX element type 'Header' does not have any construct or call signatures.ts(2604). Can someone help me fix this?

I'm using the Header comp from Semantic-ui like this, and I'm having this error for some components, not only Header. All of the components are imported but some of them are not working.
import React, { useEffect, useState } from 'react';
import logo from './logo.svg';
import './App.css';
import axios from 'axios';
import { Header, HeaderContent, List, ListList } from 'semantic-ui-react';
function App() {
const [activities, setActivities]=useState([]);
useEffect(()=>{
axios.get('http://localhost:5000/api/Activites').then(response =>{
console.log(response);
setActivities(response.data);
})
},[])
return (
<div>
<HeaderContent as='h2' icon='users' content='Reactivites' ></HeaderContent>
<ListList>
{activities.map((activity: any)=>(
<List.Item key={activity.id}>
{activity.title}
</List.Item>
))}
</ListList>
</div>
);
}
export default App;
I am using typescript on my react project and semantic-ui for styling
My package.json looks like this, and if its needed to change version of some dependencies give me suggestions on the comments
{
"name": "client-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.1.1",
"#testing-library/user-event": "^13.5.0",
"#types/jest": "^27.4.1",
"#types/node": "^16.11.31",
"#types/react": "^18.0.8",
"#types/react-dom": "^18.0.0",
"axios": "^0.27.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.1",
"semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^2.1.2",
"typescript": "^4.6.3",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"postinstall": "semantic-ui-css-patch"
},
"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"
]
}
}
I know 100% that the error its from the semantic-ui and I would appreciate so much for some help and thank you in forward
I'm new to TypeScript and its my first time using semantic-ui

Does React Typescript works in Internet Explorer 11?

I have many React applications that works in Internet Explorer 11 (With polyfills). I would like to use TypeScript in my next applications, so I developed my first one using the same technologies and concepts from the other apps. The problem is that I can just see a blank page in that browser, and many errors (Translated from Spanish):
Invalid range in character set.
Object does not accept 'repeat' property or method (This one appears 26 times).
This is my package.json:
{
"name": "reportes",
"homepage": "http://localhost:8080/isset/view/funeraria/reportes",
"version": "0.1.0",
"private": true,
"dependencies": {
"#material-ui/core": "^4.9.8",
"#material-ui/icons": "^4.9.1",
"#material-ui/lab": "^4.0.0-alpha.47",
"#mdi/js": "^5.0.45",
"#mdi/react": "^1.4.0",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"#types/jest": "^24.0.0",
"#types/node": "^12.0.0",
"#types/react": "^16.9.0",
"#types/react-dom": "^16.9.0",
"#types/react-router-dom": "^5.1.3",
"axios": "^0.19.2",
"core-js": "^3.6.5",
"exceljs": "^3.8.2",
"file-saver": "^2.0.2",
"moment": "^2.24.0",
"react": "^16.13.1",
"react-app-polyfill": "^1.0.6",
"react-dom": "^16.13.1",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.1",
"react-select": "^3.1.0",
"react-to-print": "^2.6.3",
"typescript": "~3.7.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all",
"ie 11"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version",
"ie 11"
]
}
}
And I have this imports at my index.tsx:
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';
Can you help me to fix this?
repeat is not supported by IE. You need to add polyfill for it.
For the other errors, you could also check if you used some syntax not supported by IE and try to find the polyfills for them or use some transpiler such as Babel. You could also refer to this thread.
Besides, please add import 'react-app-polyfill/ie11'; import 'react-app-polyfill/stable'; at the first line of your src/index.tsx.

react typescript testing TypeError: MutationObserver is not a constructor

I created a React app with create-react last week.
I have a simple form that displays a message when I click submit.
I would like to test it, this is the test i created SampleForm.test.tsx:
import React from "react";
import { render, fireEvent, screen, waitFor } from "#testing-library/react";
import SampleForm from "./SampleForm";
import "#testing-library/jest-dom/extend-expect"
test("renders submits form", async () => {
const str = "THIS DIDNT DO ANYTHING";
const { container, getByText, findByText } = render(<SampleForm />);
fireEvent.click(screen.getByText("Submit"));
await waitFor(() => expect(screen.getByText(str)))
});
I'm getting an error at waitFor
TypeError: MutationObserver is not a constructor
stack trace:
at node_modules/#testing-library/dom/dist/wait-for.js:38:22
at waitFor (node_modules/#testing-library/dom/dist/wait-for.js:31:10)
at node_modules/#testing-library/dom/dist/wait-for.js:70:54
at node_modules/#testing-library/react/dist/pure.js:51:22
at node_modules/#testing-library/react/dist/act-compat.js:60:24
at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:21856:12)
at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:929:14)
at node_modules/#testing-library/react/dist/act-compat.js:59:20
at asyncAct (node_modules/#testing-library/react/dist/act-compat.js:38:14)
at Object.asyncWrapper (node_modules/#testing-library/react/dist/pure.js:50:35)
at waitForWrapper (node_modules/#testing-library/dom/dist/wait-for.js:70:35)
at Object.<anonymous> (src/components/SampleForm.test.tsx:18:11)
I have tried several different alterations of the style and text querying. Derived off of the samples here
This is the straight example i'm trying to get to work
I'm hesitant about adding shims and gyrations because according to the example I shouldn't have to do any of that. I'd like to understand why that example isn't working.
My package.json:
{
"name": "intact",
"version": "0.1.0",
"private": true,
"dependencies": {
"#rjsf/core": "^2.0.0-alpha.6",
"#testing-library/jest-dom": "^5.3.0",
"#testing-library/react": "^10.0.2",
"#testing-library/user-event": "^10.0.1",
"#types/jest": "^25.1.5",
"#types/lodash": "^4.14.149",
"#types/react": "^16.9.0",
"#types/react-dom": "^16.9.0",
"#types/react-router-dom": "^5.1.3",
"bootstrap": "^4.4.1",
"lodash": "^4.17.15",
"msal": "^1.2.2",
"react": "^16.13.1",
"react-aad-msal": "^2.3.4",
"react-bootstrap": "^1.0.0",
"react-dom": "^16.13.1",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.1",
"typescript": "^3.8.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"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"
]
},
"devDependencies": {
"#types/fs-extra": "^8.1.0",
"#types/node": "^13.11.0",
"#types/rimraf": "^3.0.0",
"fs-extra": "^9.0.0",
"rimraf": "^3.0.2",
"ts-node": "^8.8.1"
}
}
edits: 04-05-2020
Are you running latest CRA? If so then this issue https://github.com/facebook/create-react-app/pull/8362 might be what you're experiencing. That's solvable by installing https://www.npmjs.com/package/jest-environment-jsdom-sixteen, e.g. $ yarn add -D jest-environment-jsdom-sixteen and editing your test script:
...
"scripts": {
...
- "test": "react-scripts test --env=dom"
+ "test": "react-scripts test --env=jest-environment-jsdom-sixteen"
...
},
...
"devDependencies": {
...
"jest-environment-jsdom-sixteen": "^1.0.3",
...
},
...
Essentially you will tell your jest to use jsdom v16 instead of v15(default for Jest v25).
I also faced the same issue.
Before trying the accepted answer, I updated react-scripts to version 4.0.1.
That solved the issue, because react-scripts 4.0.1 uses Jest 26.6.x.
Therefore, try upgrading react-scripts first.
I had this problem when I was running a very old version of node.js on Windows. When I updated to node version 12.16.3, the error disappeared.
This is my scene:
jest.config.js:
module.exports = {
preset: 'ts-jest/presets/js-with-ts',
testEnvironment: 'enzyme',
setupFilesAfterEnv: ['jest-enzyme'],
setupFiles: ['./jest.setup.js'],
testEnvironmentOptions: {
enzymeAdapter: 'react16',
},
};
package.json:
"#testing-library/jest-dom": "^5.11.6",
"#testing-library/react": "^11.2.2",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5",
"jest": "^26.6.3",
"jest-environment-enzyme": "^7.1.2",
"jest-enzyme": "^7.1.2",
"ts-jest": "^26.4.4",
"typescript": "^4.1.2"
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-router-dom": "^5.2.0",
Got error:
TypeError: MutationObserver is not a constructor
9 | const { getByTestId } = render(<Login />);
10 | expect(getByTestId('getUrl').getAttribute('href')).toEqual('');
> 11 | const url = await waitFor(() => getByTestId('getUrl'));
But when I changed the testEnvironment configuration:
module.exports = {
preset: 'ts-jest/presets/js-with-ts',
// testEnvironment: 'enzyme',
setupFilesAfterEnv: ['jest-enzyme'],
setupFiles: ['./jest.setup.js'],
testEnvironmentOptions: {
enzymeAdapter: 'react16',
},
};
The test passes:
PASS examples/65336283/LoginLink.test.tsx
65336283
✓ should display loginurl (23 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 3 s, estimated 4 s
In my case, I was updating from an old version of jest and had to make sure to include the appropriate testing environment in package.json as none was set:
{
...
"scripts": {
...
"test": "jest --env=jsdom"
...
},
...
}

Resources