I wonder why React can't find '#bootstrap-styled/v4'.
At first, I didn't eject. Because it's my first React project. I want simple.
yarn add '#bootstrap-styled/v4'
So this package installed in 'Project/node_modules/#bootstrap-styled/v4'.
And package.json file here.
# package.json
{
"name": "front",
"version": "0.1.0",
"private": true,
"dependencies": {
"#bootstrap-styled/v4": "bootstrap-styled/v4",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1",
"styled-components": "^5.1.1"
},
"scripts": {
"start": "cross-env NODE_PATH=src react-scripts start",
"build": "cross-env NODE_PATH=src 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": {
"cross-env": "^7.0.2"
}
}
# src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import 'index.css';
import BaseLayout from 'BaseLayout';
import * as serviceWorker from 'serviceWorker';
ReactDOM.render(
<React.StrictMode>
<BaseLayout />
</React.StrictMode>,
document.getElementById('root')
);
serviceWorker.unregister();
# src/BaseLayout.js
import React, { useState } from 'react';
import {
Nav,
NavItem,
NavLink,
NavDropdown,
DropdownToggle,
DropdownMenu,
DropdownItem,
} from '#bootstrap-styled/v4';
// root component
function BaseLayout() {
const [isOpen, setIsOpen] = useState(false);
return (
<Nav>
<NavItem>
<NavLink href="">Home</NavLink>
</NavItem>
<NavDropdown isOpen={isOpen} toggle={() => setIsOpen(true)}>
<DropdownToggle>
General
</DropdownToggle>
<DropdownMenu>
<DropdownItem>1</DropdownItem>
<DropdownItem>2</DropdownItem>
<DropdownItem>3</DropdownItem>
</DropdownMenu>
</NavDropdown>
</Nav>
);
}
export default BaseLayout;
I ran the server, error displayed.
Module not found: Can't resolve '#bootstrap-styled/v4' in 'D:\Project\src'
I have a few questions here.
I heard if you don't eject, React project will find module in src only. Is that right?
1-1. If correct, I don't make sense. Then why does node_modules exist? It would be right to go inside src, right?
What mean '#'? This isn't a scoped package, is it? Cause scoped package's structure is #scope/packageName. '#bootstrap-styled/v4' does not apply. (At https://bootstrap-styled.github.io/bootstrap-styled/, you can see their packages.)
Related
Image of Error
Facing an error while coding using React.js. I have know idea about it. Hence i don't know how to ask this question. Besides, I have attached an image of an error file. Putting the App.js, Header.js and package.json files. I have been trying to resolve the issue for an hour but couldn't get the success. Please help.
App.js
import { Fragment } from "react";
import Header from "./components/Layout/Header";
function App() {
return (
<Fragment>
<Header/>
</Fragment>
);
}
export default App;
Header.js
import React, {Fragment} from 'react'
import mealsImage from '../../assets/meals.jpg'
import classes from './Header.module.css'
const Header = (props) => {
return (
<Fragment>
<header className={classes.header}>
<h1>ReactMeals</h1>
<button>Cart</button>
</header>
<div className={classes=['main-image']}>
<img src={mealsImage} alt='A Table full of delicious meals' />
</div>
</Fragment>
)
}
export default Header
Package.json
{
"name": "react-complete-guide",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^13.5.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "^5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"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"
]
}
}
Try to change the className of the img container to:
<div className={classes['main-image']}>
You have issue in Header.js file, let me provide you fix code
import React, {Fragment} from 'react'
import mealsImage from '../../assets/meals.jpg'
import classes from './Header.module.css'
const Header = (props) => {
return (
<Fragment>
<header className={classes.header}>
<h1>ReactMeals</h1>
<button>Cart</button>
</header>
<div className={classes['main-image']}> {/* issue was here you were using classes=['main-image'], you do not need = here */}
<img src={mealsImage} alt='A Table full of delicious meals' />
</div>
</Fragment>
)
}
export default Header
I am having an issue defining env file in react app using the npx create-react-app my-app --template typescript, below are all the needed info on how the structure is shouldn't the env file work right out of the box ? or is this some new issue ? , basically I didn't touch any think after creating the app just put the console log in the app js so I could see the behavour.
import React from 'react';
import logo from './logo.svg';
import './App.css';
function App() {
console.log(process.env);
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;
// .env file
REACT_APP_PAYPAL_CLIENT_ID : AWLe2ytIee-lQTYPM_1v1fSnXxiJj-xDgr0xngrbX2vIDNA0zPw_028LsGlLBStEeHhTFzsnLjvqIPij
// Package
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.16.1",
"#testing-library/react": "^12.1.2",
"#testing-library/user-event": "^13.5.0",
"#types/jest": "^27.4.0",
"#types/node": "^16.11.21",
"#types/react": "^17.0.38",
"#types/react-dom": "^17.0.11",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0",
"typescript": "^4.5.5",
"web-vitals": "^2.1.3"
},
"scripts": {
"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"
]
}
}
From the Adding Development Environment Variables In .env,
The format should be key=value, NOT key: value. Replace : to =
.env:
REACT_APP_PAYPAL_CLIENT_ID=AWLe2ytIee-lQTYPM_1v1fSnXxiJj-xDgr0xngrbX2vIDNA0zPw_028LsGlLBStEeHhTFzsnLjvqIPij
created a new project by using npx create-react-app newproject. Index.js inside /src keeps getting ignored when trying to upload it to github. Everything gets uploaded correctly. Is this a problem with webpack, any dependencies? This is unusual.
folders and such:
index.js:
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
);
reportWebVitals();
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;
.gitignore:
node_modules
build
package.json:
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.16.1",
"#testing-library/react": "^12.1.2",
"#testing-library/user-event": "^13.5.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0",
"web-vitals": "^2.1.3"
},
"scripts": {
"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": {
"mini-css-extract-plugin": "2.4.5"
}
}
Uploading process: git add . && git commit -m "commit message here" && git push origin main
I'm a beginner at React app, I just finished setting up the app and want to use material UI for buttons.
Here's my code.
import Button from '#material-ui/core/Button';
import React from 'react';
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className = "App">
<header className='App-header'>
<Button>Click here</Button>
<img src={logo} className="App-logo" alt="logo" />
</header>
</div>
);
}
export default App;
I run that and it gives me Error: Invalid hook call. Hooks can only be called inside of the body of a function component. and the error points to:
4 | import App from './App';
5 | import reportWebVitals from './reportWebVitals';
6 |
> 7 | ReactDOM.render(
8 | <React.StrictMode>
9 | <App />
10 | </React.StrictMode>,
This is my package.json just in case, but I don't think there's anything wrong there.
{
"name": "schedule",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^11.2.7",
"#testing-library/user-event": "^12.8.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.2"
},
"scripts": {
"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"
]
}
}
I've spent so much time trying to fix this, please help
I have reproduced your code in this example
https://codesandbox.io/embed/dreamy-euler-jhu8t?fontsize=14&hidenavigation=1&theme=dark
Need only install material ui with
// with npm
npm install #material-ui/core
// with yarn
yarn add #material-ui/core
And delete if no need
from './reportWebVitals'
I just needed to do npm install #material-ui/core in the terminal. It wasn't in the dependencies list before. Thanks to #Claire Lin.
I was trying to add search icon from material UI but I am getting this error. "Error: Invalid hook call. Hooks can only be called inside of the body of a function component." I was trying the amazon clone tutorial from YouTube and did everything exactly. Can someone help me? Thank you.
This is my Header.js
import React from "react";
import "./Header.css";
import { Link } from "react-router-dom";
import SearchIcon from '#material-ui/icons/Search';
function Header() {
return (
<nav className="header">
{/* Logo on the left -> img */}
<Link to="/">
<img className="header__logo" src="/logo.png"></img>
</Link>
{/* Search box */}
<input type="text" className="header__serachInput"/>
<SearchIcon />
{/* Links */}
{/* Basket icon with number */}
</nav>
)
}
export default Header
Package.json
{
"name": "amazon-clone",
"version": "0.1.0",
"private": true,
"dependencies": {
"#material-ui/core": "^4.11.2",
"#material-ui/icons": "^4.11.2",
"#testing-library/jest-dom": "^5.11.9",
"#testing-library/react": "^11.2.3",
"#testing-library/user-event": "^12.6.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"web-vitals": "^0.2.4"
},
"scripts": {
"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"
]
}
}
Your code looks pretty fine and I don't see the use of hooks in your code here.
Try updating your react-dom module.
See the update error here