Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28165
| Path | csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: Javascript Module |
| Date | Thu, 25 Jun 2015 20:48:59 +0200 |
| Organization | PointedEars Software (PES) |
| Lines | 60 |
| Message-ID | <10183241.khqZmVDl6i@PointedEars.de> (permalink) |
| References | <8081bb27-e80e-40ce-b19f-4ca084324447@googlegroups.com> <558c0b0a$0$2954$e4fe514c@news2.news.xs4all.nl> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1435258329 3896 eJwNyscBACAIA8CVaAkyjlj2H0HvfXAqVwbBwMWVNuds0MsnuqhRZcotI/u3lhz7wFSWKMoe/dIPrA== (25 Jun 2015 18:52:09 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Thu, 25 Jun 2015 18:52:09 +0000 (UTC) |
| User-Agent | KNode/4.14.2 |
| X-User-ID | eJwFwYEBwDAEBMCVivxjHCT2H6F3MArHD8GDxSrdRLKoldEppE29dnjFbD22Rwb6qmCXErgMe6uf95bKDz+lFUg= |
| Cancel-Lock | sha1:udRwUh0mWClF3gGKdNce7/Rfiz0= |
| X-NNTP-Posting-Host | eJwNyEkBACAIBMBKnIvGEYT+EXSe4wpGhcFhPj5xSSU6Woia9WRtwR9eCwLP1LtPpf3vydYHC/ARKg== |
| Xref | csiph.com comp.lang.javascript:28165 |
Show key headers only | View raw
Erwin Moller wrote:
> On 6/24/2015 3:43 PM, dc7669@hotmail.com wrote:
>> I am new to Javascript and trying to learn about modules.
>> […]
> <script src="./require.js"> </script>
The “data-main” attribute is missing here, see below.
>> // main.js
>> var greetings = require("./greetings.js");
>> […]
>>
>> greetings.js
>> module.exports = {
>> sayHelloInEnglish: function() {
>> return "HELLO";
>> },
>> sayHelloInSpanish: function() {
>> return "Hola";
>> }
>> };
>>
>> […]
>> 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.
>
> Have you checked your path(s) in require.config?
> http://requirejs.org/docs/api.html#config
Configuration of paths is unnecessary in this case (so is writing the “.js”
suffix). However, the unnecessary configuration could be erroneous.
> Also, but that is not your problem, your functions return a string, […]
>
> So you must do something with that, like console.log() or alert() […]
I do not think any of this is going to help much. The OP appears to have
confused Node.js modules (as indicated by the “module.exports”) with
CommonJS’s Asynchronous Module Definition (AMD) modules.
RequireJS explicitly supports only the latter approach, and it says so in
the documentation. That is why it complains that no such module has been
loaded – there is *no* module that it can load.
<http://requirejs.org/docs/start.html#add>
<http://requirejs.org/docs/whyamd.html#definition>
That said, this newsgroup is _not_ the RequireJS support.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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