My app does not recognize react-bootstrap styles - reactjs

I am trying to make an app with react. I want to use react bootstrap. I downloaded bootstrap and react bootstrap in the project.
`
npm i bootstrap#5.2.3
`
`
npm install react-bootstrap bootstrap
`
this is my package.json:
enter image description here
I have imported the css in the App.js, I have also tried to import it in the index.js, but it still doesn't recognize it.
enter image description here
I have copied the link in the index.html of the public folder
enter image description here
when importing react bootstrap components I have done the imports for each component, but it doesn't recognize the styles, my 'card' looks like this : enter image description here
enter image description here
I don't know if I'm missing some import, or some npm to do. I have changed the imports of site a thousand times and it still does not work. does anyone know what could be happening?

1.) install bootstrap from npm package
npm install bootstrap
2.) Open your index file (Index.js) and have these two lines there like so
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import 'bootstrap/dist/css/bootstrap.min.css'; //<-- Add this
import 'bootstrap/dist/js/bootstrap.bundle.min'; // <-- Add this
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
reportWebVitals();
3.) Add button to see if Bootstrap button does show in App.js
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
<a className="btn btn-primary"
data-bs-toggle="collapse"
href="#collapseExample"
role="button"
aria-expanded="false"
aria-controls="collapseExample">
Bootstrap button
</a>
</header>
</div>
);
}
export default App;
4.) Run app with npm start and see if your bootstrap has been installed and ready to go. My case

Related

launching ios simulator with expo, receiving 'Unable to resolve module'

Please see image below to assist. I can't seem to work out where i'm going wrong?
This is my first time using expo so I am fairly confused with it. I'm trying to launch my react app on the ios simulator but receiving the error message;
iOS Bundling failed 18ms
Unable to resolve module ./App from /Users/luke/Desktop/Projects/simulate/index.js:
None of these files exist:
* App(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
* App/index(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
1 | import { registerRootComponent } from 'expo';
2 |
> 3 | import App from './App';
INDEX.JS
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './Components/App/App';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
APP.JS
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
This is happen because you deleted your App.js from your tree, so your project is trying to get access to a file that doesn´t exist
You must have something like this:
enter image description here

My Material UI button is not showing up and making nothing show up in my web app

I'm trying to use Material UI to use buttons in my web app using ReactJS for the frontend. I installed Material UI with the terminal command
npm install #material-ui/core
And my code looks like this:
import React from 'react';
import './Header.css';
import { Button } from '#material-ui/core';
function Header() {
return (
<div className="header">
<div className="headerRight">
<h1>Hi There</h1>
<img
className="headerIcon"
src="https://upload.wikimedia.org/wikipedia/commons/a/a8/Bill_Gates_2017_%28cropped%29.jpg"
alt=""
/>
<div className="button">
<Button>Click Me</Button>
</div>
</div>
</div>
);
}
export default Header;
and the compiler says "Compiled Successfully!" when I hit save, but when I look at the app in my browser, nothing is there at all. When I take out the button, everything else shows up, but when I put the button back in, nothing shows up, and I get a blank screen. I'm really frustrated trying to figure out why the Material UI button does not work. Please help me.
My App.js code looks like this
import './App.css';
import React from 'react';
import Header from './Header';
import Banner from './Banner';
function App() {
return (
<div className="App">
<Header/>
<Banner/>
</div>
);
}
export default App;
Issue for me was that I had installed MUI before jumping into my react ap (cd my-app), so the MUI package was in a parent "Node Modules" directory of my react app.
Deleted the parent Node Modules directory and reinstalled MUI in my react app.

How to use ts-nameof with create-react-app or craco?

I want to use ts-nameof in my React app created with create-react-app. How can I do that without ejection?
Hint: I also use craco, so a solution involving craco would be also fine for me.
Thanks!
It's possible to achieve with babel-macro called ts-nameof.macro without ejecting.
I've tested on fresh application generated with:
npx create-react-app temp --template typescript
# install macro dependecies
yarn add -D ts-nameof.macro
# or
# npm i --save-dev ts-nameof.macro
NOTE: if your react-scripts version lower than 2.0, you also need to install babel-plugin-macros as dev dependency.
Update App.tsx
import React from 'react';
import nameof from "ts-nameof.macro"; // import nameof
import logo from './logo.svg';
import './App.css';
function App() {
console.log(nameof(window.alert)) // "alert"
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;

Why does jest testing break when adding react-router-dom to a react app with create-react-app

I am running a create-react-app with react-16.8.6, and no modifications except for adding react-router to the mix. Now tests don't work.
After rolling things back, I found that the base test fails as soon as I import ANY part of the "react-router-dom" library. Any ideas whats going wrong?
Below is the App.js and App.test.js when I comment out the line:
import { Switch } from "react-router-dom";
the tests run without issue. When I return the line to the code I get the following error:
Test suite failed to run
Cannot find module 'react' from 'react-router-dom.js'
However, Jest was able to find:
'./App.css'
'./App.js'
'./App.test.js'
App.js
import React from "react";
import { Switch } from "react-router-dom";
import logo from "./logo.svg";
import "./App.css";
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
app.test.js
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
it("renders without crashing", () => {
const div = document.createElement("div");
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
That might be some package manager installation issues. Try to do a fresh install:
rm -rf ./node_modules && rm yarn.lock && yarn
or in case if you're using npm:
rm -rf ./node_modules && rm package-json.lock && npm install
BTW, what is the version of the react-router-dom that you're installing? I've just tried it on the new create-react-app project, installed the latest version of router, but can't reproduce this error ()
Ran into the same issue, and was thinking I could elaborate on the solution for people who run into the same.
It is not resolved by deleting node_modules and yarn.lock/package-lock.json. Instead, as #Finglish mentions in their comment above, you probably have missing dependencies.
To fix the missing deps:
Get the depcheck package.
Run it in your project folder to see which dependencies you're missing.
Install the missing dependencies.
Run tests again to make sure everything is working.

A dependency to an entry point is not allowed in multiple page app with react

I carefully searched the same problem that I faced but didn't find anything helpful.
webpack 1.13.1. Mac OS X El Capitan last version.
What I am trying to accomplish
I want to create a webpack build to develop multiple page apps.
I want to see the structure like this:
source
/source/page1/page1.css
/source/page1/page1.js
/source/page1/page1.html
public
/public/page1/page1.css
/public/page1/page1.js
/public/page1/page1.html
Current build
This is what I've done.
https://gist.github.com/lavezzi1/9cc0e58cd7d2b8f2470e703022a41db7
I tested it with vue.js and it works perfect. But now I want to get it works with react.js as well.
In dev move everything works just fine but when I ran task for prod build I got this error:
ERROR in ./source/pages/index.js
Module not found: Error: a dependency to an entry point is not allowed
What I did. This is my page folder:
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';
ReactDOM.render(
<App />,
document.getElementById('root')
);
App.js
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
class App extends Component {
render() {
return (
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Welcome to React</h2>
</div>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
</div>
);
}
}
export default App;
So what am I doing wrong? I am newbie in react.js, maybe I don't understand something.
In vue.js I just create files:
index.html
index.css
index.vue
index.js
And everything works as expected.
I really really hope you guys help me.
why don't you just indicate the js file as entry point and import the css in that entry file. For multiple js entry file you can use the code splitting feature of webpack.
https://webpack.github.io/docs/code-splitting.html
and in your webpack.config.js file you can define entry file like the following.
entry: {
lite: "./lite.js", pro: "./pro.js",
},
output: { filename: "dist/[name].js" },

Resources