I have created a new reactjs project using create-react-app and am finding it's not working on IE10 & IE9. I have done a lot of research and it led me to using polyfills, which I have done with many of my other Rails on React app, but I'm finding it not working with this project created via create-react-app.
Here's the error:
SCRIPT5009: 'Map' is undefined
I notice this error is related to ES6's new Map() function.
So, here's what I've done in my code in an attempt to make it work:
import './polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { BrowserRouter } from 'react-router-dom';
import 'bootstrap/dist/css/bootstrap.min.css';
const app = (
<BrowserRouter basename={process.env.PUBLIC_URL}>
<App />
</BrowserRouter>
);
ReactDOM.render(app, document.getElementById('root'));
Polyfill.js:
import 'core-js/es6/map';
import 'core-js/es6/set';
import 'core-js/fn/object/assign';
This isn't working. I'm not sure what else to try. I've tried a lot of other polyfill imports as well and continue to get the same error.
Any help would be appreciated!
So, seeing as though create-react-app is what's restricting me from controlling the webpack config, I decided to take a different approach and build a fresh react app using webpack 4. I followed this article, https://dev.to/saigowthamr/how-to-create-a-react-app-from-scratch-using-webpack-4-1909.
This allowed me more control over the webpack config and now the polyfill loaders are working.
Nevertheless, if anyone has an explanation as to why it wasn't working with create-react-app, I think it'd be helpful for the community to know.
Thanks!
Related
There is a ready front-end built using React.
Is it correct to connect it?
So far, there is only 1 page with one div block in which there are pictures. I read the documentation and didn't quite understand how it was done.
Can you please describe in detail all the steps to enable it?
I have a fresh/clean Laravel project. I don't know Laravel & React well yet. Therefore, I ask you to tell in detail and step by step all the actions so that React styles work in welcome.blade.php.
React structure (src/index.js):
import React from 'React';
import ReactDOM from 'react-dom/client';
import './index.scss';
import App from './App';
import 'macro-css';
const root = ReactDOM.creactRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App/>
</React.StrictMode>
);
I tried to migrate the code from React index.js into Laravel's app.js and I threw all the other files next to it in the hope that it would work.
Please, first go through the Laravel Bootcamp which will take you through how Laravel integrates with React.
Writing Views In React / Vue
Our Breeze and Jetstream starter
kits give you a great
starting point for your next Laravel application powered by Inertia.
In addition, the Laravel Bootcamp
provides a full demonstration of building a Laravel application
powered by Inertia, including examples in Vue and React.
We are refactoring some legacy code into React and it turns out it is all reactNative.
Does anyone have any idea how we can refactor this AppRegistry.registerComponent into React (Just regular React (like the one create-react-app installs), not React Native, not React-Web), the same goes for AppRegistry.getApplication? We don't want ANY react-native at all, so any help would be greatly appreciated...
Could someone also point me at a decent resource so I can stop asking these asinine questions? :(
You will not need AppRegistry in your case. This is the entry point for your app in react native.
AppRegistry is the JS entry point to running all React Native apps.
App root components should register themselves with
AppRegistry.registerComponent, then the native system can load the
bundle for the app and then actually run the app when it's ready by
invoking AppRegistry.runApplication.
In your app, you should refactor
// react native app
import App from "./App";
...
AppRegistry.registerComponent(appName, () => App);
to
// your new app
import App from './App';
...
ReactDOM.render(<App />, document.getElementById('root'));
I have a Next.js app with several pages in it. All of the pages look similar.
import React, { Component } from "react";
import from "components/Wrapper";
export default class About extends Component {
render() {
return <Wrapper />;
}
}
I would like to refactor it using functional component.
I read here that you don't have to import react package here in a page due to next.js routing system. Next.js docs also show examples without react import on a page component, but no explanation given.
Can you clarify please. Is it necessary to import React at all in this case? Can I remove the import React line?
Well, actually it is still a complicated issue for all of us to realise when to use import React from "react"; and when not to in Next.js apps. But according to Tim Neutkens co-author of Next.js, in this thread he mentioned:
Next.js automatically adds the React import when JSX is used indeed. However, keep in mind that we still need to import React from 'react' when the React variable is used.
So this will show us, that whenever we want to use the JSX feature alone from React we do not have to import React from 'react' and Next.js will implicitly import it for us, but in any other case, we have to do that.
Update
Since the release of react v17.*.*, there is no need to import React from 'react' to use only JSX in the React and CRA apps, but you still need to import it for the usage of the hooks and other compartments that React offers with destructured named imports.
NPM libraries/packages
Though you will still need it if you want to create an npm package with react because under the hood it is the react-scripts job to do the automatic imports and babel or rollup won't do this on their own and they've just transpile the provided code. Keep in mind even in this case the usage of import React from 'react' is discouraged because the support will be dropped in the upcoming versions, so it is highly recommended to use import * as React from 'react' in these cases.
I built an application using jhipster v5.3.4 choosing React option for frontend. It works fine with Edge and Chrome but renders a blank page on Internet Explorer 11.
I've read the solution is install and include babel-polyfill but I´m not sure how to do this.
What I've done:
npm install --save-dev babel-polyfill
At the top of index.tsx, add import babelPolyfill from 'babel-polyfill';
The result is the same, blank page and console error: "Symbol is undefined"
Finally the answer to make it works is:
import React from 'react';
import ReactDOM from 'react-dom';
import 'babel-polyfill';
I have created a simple application with react 16.2.0 and when I execute/run it on IE9 it shows me console error 'Set' or 'Map' is undefined.
I have found that there are some polyfills require to run my react application on IE9. I followed following steps and it worked for me. As React 16 depends on the collection types Map and Set. If you support older browsers and devices which may not yet provide these natively (e.g. IE < 11), consider including a global polyfill in your bundled application, such as core-js or babel-polyfill.
We also have to use requestAnimationFrame polyfill library which is raf
npm install --save raf
index.js
import 'core-js/es6/map';
import 'core-js/es6/set';
import 'raf/polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('root')
);
You should have to find and add pollyfills for set and map as well if it's not working.