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

Can't load named modules asynchronously #27

Closed
ryanflorence opened this issue Oct 13, 2011 · 2 comments
Closed

Can't load named modules asynchronously #27

ryanflorence opened this issue Oct 13, 2011 · 2 comments
Assignees

Comments

@ryanflorence
Copy link
Contributor

The error

The module at util/foo.

define('foo', { foo: 'bar' })

The loading:

require(['util/foo'], function (f) { console.log(f) });

Gives this error: Error: define() not found or duplicates found: /path/util/foo.js

RequireJS loads it just fine.

Why would we do this?!

We're migrating our codebase to AMD, but its far too large to do all at once, so we're dropping in curl.js or require.js and using it for new development, and will go back and convert old code over time.

The end goal is to use the require.js optimizer and then curl.js in the browser, but not until everything is converted to AMD. So, for the time being, we are still using our old build process to concat all our JS together with Jammit and are naming our modules by hand.

However, for our specs / development of new stuff we'll be loading things asynchronously so we need it to be able to load named modules as if they were unnamed.

tl;dr

@unscriptable
Copy link
Member

Hello Ryan,

curl.js is strict about module ids. (It seems strange to me that RequireJS is not.) I can't think of a good use case for having them be different. Try this:

The module at util/foo.

// note the module id includes the package and/or folder
define('util/foo', { foo: 'bar' })

The loading:

require(['util/foo'], function (f) { console.log(f) });

Is there a reason to have the module name not include the package/folder name? If you need it to be different for some reason, you could use the paths: {} config to map it instead.

Also: the build-time mechanics of the AMD tools are not standardized, yet. What this means to you: require.js's optimizer could do things that curl.js's loader isn't expecting. We expect to have the details agreed upon soon, though. This shouldn't be an issue for you currently unless you are using plugins. That's where the AMD build tools differ the most right now. If there are other issues, they're likely minor and can be fixed easily, I suspect.

I haven't tried using curl.js with other optimizers in a while, so I would be very interested in your success. Your feedback is greatly appreciated!

Regards,

-- John

P.S. please close this issue if/when you're satisfied with my answer and/or solution. I hate when somebody closes my tickets before I think they're closed. :)

@unscriptable
Copy link
Member

Hey Ryan. Were you able to resolve this problem? Regards, -- John

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