I am importing Routes the following way
import {Routes, Route, BrowserRouter} from 'react-router-dom'
My package JSON is "react-router-dom": "^6.0.2",
I am using Pycharm.
npm list react-router-dom returns -- react-router-dom#6.0.2
Why is this happening? My frontend is blank.
I had the exact same issue of "Cannot Resolve Symbol" for most of the imports in Intellij, when I upgraded to the react-router-dom:6.0.2.
As #DLH stated, the Jetbrains Product was reading the type file for the package from <system directory>/jetbrains/intellij/javascript/typings rather than from the node_modules folder of the project.
As said by Oksana Chumak from Jetbrains:
The IDE downloads typings for some popular libraries to its configuration folder and uses them to enhance code completion.
Solution:
Inside the jetbrains product, press shift two times to open the search everywhere window, search for registry and open the first result.
In the registry, look for typescript.external.type.defintions.packages key and in the value of that field, only remove the react-router-dom field from the values.
Also Go to File -> Invalidate Caches -> select "Clear file system cache and Local History" -> click "Invalidate and Restart"
Now, the jetbrains product will read the type file from node_modules of project, rather than reading it from its internal typings folder. In the future, It will also not try to download and use the intellij react-router-dom typings for other projects.
Credits: Props to #Mir-Ismaili and #unfestive chicken for helping out with the third step.
I just had the same problem in WebStorm. When I did the crtl-click over 'react-router-dom' in the import statement, I saw that it seemed to be confused over which index.ts.d file to pay attention to. One was from the 6.0.2 version installed in my project's node_modules as expected. The other was in C:\Users[me]\AppData\Local\JetBrains\WebStorm2021.2\javascript\typings\react-router-dom\5.3.2\node_modules#types\react-router-dom\index.d.ts.
I just renamed the latter JetBrains file from 5.3.2 figuring that it was now obsolete, and it worked as expected thereafter. It's not the prettiest solution, and I'm only mostly sure that it won't find a way to bite me in the rump later. But at least for now, it works.
We can try removing node_modules and deleting that folder.
Then we can run npm this will reinstall those packages again.
After that, I would then try implement the Router and see if it resolves itself even though it complains that it can't find the symbol.
Something like this should work:
<BrowserRouter>
<Routes>
<Route path='/*' element={ <App /> } />
</Routes>
</BrowserRouter>
I resolved the blank screen, it was because of the version so I had to change the code based on https://github.com/remix-run/react-router/blob/main/docs/getting-started/tutorial.md, but I still have a warning "Cannot resolve symbol 'Routes'"I'm using the latest version of Webstrom.
import React from "react";
import {BrowserRouter as Router, Routes, Route } from "react-router-dom";
import { Container } from "react-bootstrap";
import Header from "./components/Header";
import Footer from "./components/Footer";
import HomeScreen from "./screens/HomeScreen";
const App = () => {
return(
<Router>
<Header />
<main className='py-3'>
<Container>
<Routes>
<Route exact path="/" element={<HomeScreen />}/>
</Routes>
</Container>
</main>
<Footer />
</Router>
);
}
export default App;
You have to install Typescript stubs for the package
You have two options:
Install it with IDE
Put cursor on "react-router-dom" in import statement
hit Alt+Enter
choose Install TypeScript definitions for better type information
Install it with npm
open cmd at your project
npm install #types/react-router-dom
Don't forget to remove IDE library from Preferences | Languages & Frameworks | JavaScript | Libraries , if you used option 1
On macOS, a possible solution is this:
In your app bar, press File -> Invalidate Caches -> select "Clear file system cache and Local History" -> click "Invalidate and Restart"
Related
This is my first attempt at creating a navbar using REACT. Although webpack compiled successfully, nothing shows in my browser.
Can I have some help please? This is the github repo for the project:
https://github.com/mah752/myportfolio
thank you,
Maryan
So this looks like it's something to do with the way you have implemented your routes. If you were too boot up your app and check the console you would see.
router.ts:5 Uncaught Error: You cannot render a <Router> inside another <Router>. You should never have more than one in your app.
I have looked through your code and noticed that you have the routes in your nav bar as well as index.js so you're inserting <Router> inside another <Router> which breaking things. As <App /> has your navbar which has the <Router> component also.
I would highly suggest going through this tutorial on React Router
https://reactrouter.com/docs/en/v6/getting-started/tutorial
This will tell you how to implement your routers correctly and go over nested routes.
Also another tip. I noticed you have a lot of files in your components folder for example:
Project.js
Project.css
The best practice is to do create a directory for each component and create a css module file like so:
components/projects/... This would now look like
Project.module.css
Project.js
But going back to your issue, go through the link on React Router and you should be fine.
I've cloned your repo and I see the following error in the browser:
Module not found: Error: Can't resolve './app.css' in '/home/atota/development/myportfolio/src'
Open src/App.js and on line 10, you're doing the following import:
import "./app.css";
Whereas it should be:
import "./App.css";
Spoiler alert: after resolving this error, you'll see the following one in the Browser Dev Tools, related to your component:
Uncaught Error: You cannot render a <Router> inside another <Router>. You should never have more than one in your app.
I see you're using react-router-dom, I suggest you to take a look at the docs.
I am trying to add a plugin to the classic build of CKEditor5. I have followed the instructions on this page: https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/installing-plugins.html
I can tell that I've done everything properly since everything works as it is supposed to when I open up the sample/index.html.
Now comes the time to integrate this custom build with my react app.
The instructions on this page, 'describe' what to do:
You will create a new build somewhere next to your project and include
it like you included one of the existing builds.
It says to 'include it like you included of one of the existing builds'. Well, this is how I included the classic-build:
import React from "react";
import ReactDOM from "react-dom";
import CKEditor from "#ckeditor/ckeditor5-react";
import ClassicEditor from "#ckeditor/ckeditor5-build-classic";
import "./styles.css";
function App() {
return (
<div className="App">
<CKEditor
editor={ClassicEditor}
// Other Props
}}
/>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
So, I would assume that I would do something like this:
import React from "react";
import ReactDOM from "react-dom";
import CKEditor from "#ckeditor/ckeditor5-react";
import ClassicEditor from './ckeditor/ckeditor'
import "./styles.css";
function App() {
return (
<div className="App">
<CKEditor
editor={ClassicEditor}
// Other Props
/>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
That is, simply change the import statement from:
import ClassicEditor from "#ckeditor/ckeditor5-build-classic";
to
import ClassicEditor from './ckeditor/ckeditor'
With ./ckeditor/ckeditor/ being the ckeditor.js file found in the build folder of my modified version of the custom build.
But, this does not work. There is no export in the new ckeditor.js file. Neither a default export nor a named export. So perhaps I should import the file like this:
import './ckeditor/ckeditor'
But then how do I tell the React component which editor to use. There is an editor prop, which takes the name of the editor to use -- namely:
<CKEditor
editor={ClassicEditor}
// Other Props
/>
So I am stuck. I have no idea how to include the custom build into my react app.
Any ideas?
Thanks.
The CKEditor team helped me solve this problem. You can read the solution here: https://github.com/ckeditor/ckeditor5/issues/2072#issuecomment-534987536
The main point was that I needed to publish my customized build as an npm package, install that package on my site and then import the installed package.
Once I did that, everything worked just fine.
Forget what you know about customizing cke4 then read this
Steps to customize your CK5 Editor
fork the ckeditor5 classic build
clone your new fork
customize the ckeditor (I used the online build tool)
build the editor with $ npm build
add & commit changes
push your commits to your forked repo
clone your forked repo to your existing project and use the ckeditor from YOUR build.
This process is not very straight forward and the documentation on it is non-existent at best. Hopefully my pain is your gain!
Extra
The online build tool has you download a .zip and what I did was overwrote my forked project files with the ones form the zip. I built, uploaded, etc. Make note that the config for the toolbar is inside the sample/index.html if you don't add that then you won't see your toolbar.
Remember to add the toolbar config!
** EDIT **
If you're working on a team you'll want to go with the version at the top.
Simpler
Use the Online Build Tool
download the zip to your project
go to the folder in git and npm install
edit your ckeditor.js to include the config from sample/index.html (I put everything in my Editor.defaultConfig)
in the same folder run npm build
go to your main project and import ckeditor from the build you just made eg import ClassicEditor from './online-build/build/ckeditor';
in the project folder run npm build
If everything works except you don't have a toolbar then you need to re-examine your config setup.
Cheers!
** EDIT **
I wanted to add the "source editing" plugin which doesn't seem supported (??) What I did was manually snagged the source-editing code from the ckeditor5 main git (all the plugins are listed at the bottom) then pasted that code into my project and imported from that folder. This is all a bit chaotic and it's not suitable for teams BUT IT WORKS - good luck
import SourceEditing from './ckeditor5-source-editing/src/sourceediting.js';
I made react-app and webpack from scratch, and everything works and looks fine in webpack-dev-server. But when I build (bundle) app to file it not showing components from 'Route' path.
Webpack outputting no errors so I don't know how to fix that. This is the project: https://github.com/kamilmoskal/react-movies-library-app
Probably you were trying to open index.html as regular file in the browser. The application should be deployed on some server.
The easiest way to make it work is to serve it on you local machine using i.e. serve:
npm install serve --save
cd doc
serve
Then navigate to http://localhost:5000 in your browser
Ok i figured it out the problem was with < Route exact path='/' ... when path is like this "/", to fix that i changed:
from: import { BrowserRouter, Route, Switch } from 'react-router-dom'
to: import { HashRouter as Router, Route, Switch } from 'react-router-dom'
and in code below from: <BrowserRouter>
...
</BrowserRouter>
to: <Router>
...
</Router>
When i was doing apps throught standard 'npx create-react-app my-app' it was enough to add < BrowserRouter basename={process.env.PUBLIC_URL}> but in this case it didint work. maybe it will help someone.
I'm trying to make a react project on github pages using [username].github.io. but when I go on the link, it just returns a white screen without any error messages. This also happens when I use a custom domain name.
However, it works when I run it locally and also when I use gh-pages instead of a user repo.
I used https://medium.freecodecamp.org/surge-vs-github-pages-deploying-a-create-react-app-project-c0ecbf317089 to upload all my files into github since I created the repo at the end after I finished, but I tweaked it a little to work without gh-pages.
I also referred to this answer: hosting gh-pages on custom domain, white empty page but it didn't do anything for me.
Does anyone know how to fix this? Thanks!
Change BrowserRouter to HashRouter as follow
Before:
import { BrowserRouter } from "react-router-dom"
ReactDOM.render(
<BrowserRouter><App /></BrowserRouter>,
document.getElementById('root')
);
After:
import { HashRouter } from "react-router-dom"
ReactDOM.render(
<HashRouter><App /></HashRouter>,
document.getElementById('root')
);
Check if you're getting an error on the console. You might need to switch from BroswerRouter to HashRouter, because gh-pages doesn't work well with the former.
I am a bit late to this discussion, but I ran into this same issue and I found a solution that was not listed here.
Here is the solution I found: https://github.com/gitname/react-gh-pages/issues/3#issuecomment-399787987
The issue this user was having was related to how GitHub serves your react build from GitHub Pages. GitHub pages serves your react build from a folder names after your repository directory instead of from the root server directory "/". Hopefully this link will help someone else out in the future.
Using react router in my create-react-app i had this same issue. What solved it for me was adding this line to the router.
<Router basename={process.env.PUBLIC_URL}>
I have an app created with create-react-app boilerplate. I'm also using react router and I try to use browserHistory for clean links (no #). I follow this lesson but I fail to add --history-api-fallback to webpack dev server. I'm not familiar with devpack at all so I dont know where should I put this line so when I reload page I don't get 404 (it happens only when deploying build to server).
I already did eject with npm.
import {Router, Route, IndexRoute, IndexRedirect, browserHistory} from 'react-router';
ReactDOM.render(
<Router history={browserHistory}>
...
</Router>
, document.getElementById('root')
);
EDIT
Reloads work without configuration when I run app locally or when I tried (as suggested) with pushstate-server build. It only doesn't work when I push build to my free web hosting at openshift.com (it was working with browserHash thought)