1

I am trying to create an React component using ES6 in JSBin, but I keep on getting the below error. Can someone explain these?

JSBin Error: "ReferenceError: require is not defined at mudaza.js:17:14"

1 Answer 1

9

You cannot use imports or requires in JSBin. You need the bundled .js files of the libraries you want to use in your app in the head of your html file and then use a slightly different syntax to access the components or functions from the added libraries.

For example, to use react-router in a pen, you should add it in the head of the HTML page hosting your app:

<script src="https://cdnjs.cloudflare.com/ajax/libs/react-router/2.0.0/ReactRouter.min.js"></script>

Afterwards, in your app's source:

var { Router, Route, IndexRoute, hashHistory, Link } = ReactRouter;

instead of

import { Router, Route, IndexRoute, hashHistory, Link } from "react-router";

I've cloned and updated your JSBin with these changes.

A very good source for most modules .js files is https://cdnjs.com/.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.