Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: Can't find variable: require #2

Closed
luisfeliu opened this issue Sep 20, 2012 · 2 comments
Closed

ReferenceError: Can't find variable: require #2

luisfeliu opened this issue Sep 20, 2012 · 2 comments

Comments

@luisfeliu
Copy link

I'm sure this is just due to my limited knowledge of JavaScript, but the collections by themselves are not standalone.

Within the head of my html file, I include a js file that has the following line of code (as in the demo):

var SortedMap = require("jsCollections/sorted-map");

When the page loads, I get the following error on the console:

"ReferenceError: Can't find variable: require "

So, I tried different js "loaders" such as require.js and modules.js (this one from chiron). I also tried loading each "require" js file from collections in the html head in a particular order. For all of these efforts, I continue to get an error.

For modules.js, I add the following to the html head:

script src="modules.js?./myjsfile.js"

This results in the following errors:

TypeError: '[object Object]' is not a constructor (evaluating 'new SortedMap()') modules.js:445
(anonymous function) modules.js:445
(anonymous function) modules.js:349
(anonymous function) modules.js:91
(anonymous function) modules.js:493
TypeError: '[object Object]' is not a constructor (evaluating 'new SortedMap()')

If I add each require in the html head like this:

script src="jquery.js"
script src="jsCollections/sorted-map.js"
script src="jsCollections/sorted-set.js"
script src="jsCollections/reducible.js"
script src="jsCollections/operators.js"
script src="jsCollections/tree-log.js"
script src="jsCollections/abstract-map.js"
script src="myjsfile.js"

I get the following errors on the console:

ReferenceError: Can't find variable: require sorted-map.js:2
ReferenceError: Can't find variable: module sorted-set.js:2
ReferenceError: Can't find variable: module reducible.js:2
ReferenceError: Can't find variable: exports operators.js:9
ReferenceError: Can't find variable: module tree-log.js:2
ReferenceError: Can't find variable: module abstract-map.js:2
ReferenceError: Can't find variable: require myjsfile.js:1

If it helps, I'm using jquery which I load first in the html head and I'm using a webkit browser compiled with QT for Linux (Ubuntu).

I would appreciate any help that would allow me to load and run the js collections. I suppose that I need to add a js loader. I would prefer this loader to be of a minimal file size.

If the issue is not clear please let me know so that I can clarify it. As a recap, I cannot run the js collections just by themselves because of the require, module, and exports functions/variables. I need to understand what else is needed to run the js collections.

Thanks in advance.

@kriskowal
Copy link
Member

For development, I recommend using the Montage Require loader, https://github.com/kriskowal/mr. The loader in Chiron is ancient in comparison.

For production, you might try https://github.com/substack/node-browserify. I haven’t tried that one yet, but it should work.

@luisfeliu
Copy link
Author

I will give those a try. Thanks a lot for the prompt response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants