I've attached copies of the code below. Only two files in my project now, app.js and index.html. When I go to google developers' tool and console, the log statement isn't going through. When I type react or react-dom into console I am told Reference Error: React is not defined. This is what a Udemy tutorial has told me to do last updated 5/19 so this should work. I have tried putting import React from "react"; in the top of the files but that doesn't work either. Any suggestions?
//app.js
console.log("App.js is running!)
//index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Indecision App</title>
</head>
<body>
<script src="https://unpkg.com/react#16.0.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom#16.0.0/umd/react-dom.development.js"></script>
<script src="/scripts/app.js"></script>
</body>
</html>
Looks like you'll need to also specify the crossorigin attribute on the scripts as per the react CDN-links docs.
<script crossorigin src="https://unpkg.com/react#16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom#16/umd/react-dom.development.js"></script>
Related
I'm using the code generated from the Facebook code generator here https://developers.facebook.com/docs/plugins/comments/ and as instructed I've created a HTML file with the following code in it.
<html lang="en">
<head>
<title>Home</title>
</head>
<body>
<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v11.0" nonce="PMiduXpV"></script>
<div class="fb-comments" data-href="https://developers.facebook.com/docs/plugins/comments#configurator" data-width="1" data-numposts="1"></div>
</body>
</html>
however, nothing is displayed on the UI. I can only access the comments if I manually inspect the page and manually navigate through the loaded Iframe.
Any ideas why this might be happening?
I have a single HTML page with React (build manually without ANY tools, just a text editor).
This page is working correctly. Now, I would like to add a PIE Chart with NIVO lib.
When I add the script (CDN) I got the following error in console:
exports is not defined
I can solve this by creating a fake exports var = {} (is that a good solution ?)
But then I have a new error:
require is not defined
Do that means the CDN link from NIVO is incorrect ? How to solve this ?
Alternative: I am open to use another lib working with React. But I want to only use CDN links and a text editor to achieve that.
Full HTML file:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Batch stats</title>
<script>let exports = {};</script>
<script src="https://unpkg.com/#babel/standalone/babel.min.js"></script>
<script crossorigin src="https://unpkg.com/react#16.7.0/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom#16.7.0/umd/react-dom.production.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/#nivo/pie#0.61.1/dist/nivo-pie.cjs.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
function Page(props) {
return (
<div>
<h1>Hello World</h1>
<div>How to add a PIEChart ?</div>
</div>
);
}
ReactDOM.render(<Page version="v3"/>, document.getElementById('root'));
</script>
</body>
</html>
Thanks
Nivo do not support it.
you should use the UMD build, however, you'll need a bunch of extra
dependencies, including D3 packages which are using modern JS
features.
https://github.com/plouc/nivo/issues/959
When I load the library from an url, my code works as intended but when I try to load the same library from my local drive it spits out the error:
Uncaught ReferenceError: quat is not defined
at main (main.js:3)
at onload (index.html?_ijt=h48f9s7rceh7l34tfquh6ab8n5:7)
main # main.js:3
onload # index.html?_ijt=h48f9s7rceh7l34tfquh6ab8n5:7
What am I doing wrong in second case?
//index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body onload="main()">
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/gl-matrix/2.8.1/gl-matrix.js"></script>-->
<script src="Libraries/gl-matrix.js"></script>
<script src="main.js"></script>
</body>
</html>
//main.js
function main()
{
let x = quat.create();
console.log(x);
}
Your main.js file is loading before the main plugin script loading change the order like this.
<script src="Libraries/gl-matrix.js"></script>
<script src="main.js"></script>
first, please try changing the order of your <script> tags. Try loading the gl-matrix.js file first. Additionally you should make sure to provide either an absolute path to your local gl-matrix.js file or a path relative to the location of the file your <body>tags are located in.
Best Regards,
Bachkippe
Hi guys can you help me I'm just starting to learn angularjs. How to deal with these errors
app.js:6 > Uncaught ReferenceError: angular is not defined
angular.min.js:6 > Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.20/$injector/modulerr?p0=ajs&p1=Error%3A%20…%2F%2FC%3A%2FUsers%2FABK3%2FDesktop%2Fajs%2Fjs%2Fangular.min.js%3A18%3A139)
Thanks in advance guys
var app = angular.module('ajs', ['ui.router'])
<!DOCTYPE html>
<html ng-app="ajs">
<head>
<meta charset="utf-8">
<title>AJS</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<h1 ui-view>Hi</h1>
</body>
<script src="app.js"></script>
<script src="js/angular.min.js"></script>
<script src="js/angular-ui-router.min.js"></script>
<script src="jquery/jquery.min.js"></script>
</html>
Make sure your scripts are loaded after angular so they can actually do something. The load order is important, for instance make sure to load jQuery before anything, almost all the libraries requires them to be previously loaded.
<!-- Load vendors -->
<script src="jquery/jquery.min.js"></script>
<script src="js/angular.min.js"></script>
<script src="js/angular-ui-router.min.js"></script>
<!-- Load source code -->
<script src="app.js"></script>
You must put all of your script tags that calls angular BEFORE your app.js because your app.js needs angular.
Because here your file loads app.js then angular
I'm trying to run a Angular2 app from WAMP on my local pc.
I develop the app from the wamp/www folder and test it at different stages both from localhost:3000 and localhost/myapp (liteserver and wamp)
All works fine until i try to add <base href="/"> to Index.html right below the <head>.
At that point, only in Wamp i get the error: ReferenceError: System is not defined
Is there any workaround or fix to get past this error? (and move to the next one :) )
This is my Index.html.
<html>
<head>
<base href="/">
<title>Firebase</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
Update:
LiteServer working, Folder Structure, and main.ts:
WAMP, Index.html
I was just reading about the new angular2 router and i thought to try this:
<base href=".">
and it just works with no further errors!!
I can't tell why, but both wamp and liteserver work fine now, even though in all tutorials about router they all show this method: <base href="/">. I hope this will help someone else to waste less time on this silly thing then i did.