最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - "ReferenceError: require is not defined", while creating React component using ES6Babel - Stack O

programmeradmin0浏览0评论

I am trying to create an React ponent 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"

I am trying to create an React ponent 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"

Share Improve this question asked Mar 8, 2016 at 15:23 Aditya SinghAditya Singh 16.7k15 gold badges48 silver badges69 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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 ponents 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./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./.

发布评论

评论列表(0)

  1. 暂无评论