Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28151

Javascript Module

Newsgroups comp.lang.javascript
Date 2015-06-24 06:43 -0700
Message-ID <8081bb27-e80e-40ce-b19f-4ca084324447@googlegroups.com> (permalink)
Subject Javascript Module
From dc7669@hotmail.com

Show all headers | View raw


I am new to Javascript and trying to learn about modules.

I have this greetings-main.htm: 
<html>
<script src="./require.js"> </script>

<script>


// main.js
var greetings = require("./greetings.js");

// "Hello"
greetings.sayHelloInEnglish();
         
// "Hola"  
function Test(){
    greetings.sayHelloInSpanish();
}

console.log(Test());
console.log('12345967890');
                         
</script>

</html>

greetings.js
module.exports = { 
    sayHelloInEnglish: function() {
    return "HELLO";
  },
    sayHelloInSpanish: function() {
    return "Hola";
  }
};

I got require.js. This is the information about require.js
/** vim: et:ts=4:sw=4:sts=4
 * @license RequireJS 2.1.18 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved.
 * Available via the MIT or new BSD license.
 * see: http://github.com/jrburke/requirejs for details
 */


The problem is that when I run greetings-main.htm,  I got an error saying, "require.js:166 Uncaught Error: Module name "greetings.js" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded"

What did I do wrong?  greetings.js file exists in the same directory of greetings-main.htm.  

Any help will be appreciated.  

Thanks.

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Javascript Module dc7669@hotmail.com - 2015-06-24 06:43 -0700
  Re: Javascript Module Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-06-25 16:07 +0200
    Re: Javascript Module Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-25 20:48 +0200
  Re: Javascript Module "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-06-25 16:47 +0200

csiph-web