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
Relative module path resolution fails after loading from absolute path #230
Comments
This is my (certainly wrong) workaround in nameToUrl() function:
|
Sorry, I meant to comment sooner: I expect that if you create a paths entry for it in the config call it should work out: requirejs.config({
paths: {
'remoteModule': 'http://other.domain/remoteModule'
}
});
//Then later...
require (['remoteModule'], function (RemoteModule) {
}); The full URL support in requirejs is really just to help easily incorporate non-module scripts into a project. However, for modules, it is best to use module naming with path entries. This also opens up the possibility of mapping that dependency to a local file in a build. |
Ah, one adjustment to the above: module IDs are resolved relative to other modules IDs, not paths. So the above config and module ID use should really be: requirejs.config({
paths: {
'remote': 'http://other.domain'
}
});
//Then later...
require (['remote/remoteModule'], function (RemoteModule) {
}); Note the usage of a prefix "remote" for the ID. So if remoteModule.js has a './something' module ID reference, it is resolved to 'remote/something' which then gets that above path applied to it. |
@jrburke I actually just ran into this issue as well, and I cannot put in a "path" entry. In my case, I load In The above fails because, because now require tries to load the absolute path I also can't change Is there any way to fix it or work around it? Using a 'path' definition isn't really an option in our case. |
@itay to use relative ids in a module, requirejs has to understand the id of the module that's using relative ids (think of module ids as a separate namespace to URLs). if your the |
@neonstalwart I'm not 100% sure I follow. Let me give a more formal sample: Directory:
module1.js:
module2.js:
I guess my confusion stems from the fact that if I do this: doesntwork.html:
It doesn't work, because what require.js ends up doing is trying to loading I don't see why it changes whether the extension is added or not based on how the module was originally required. Because if I do this instead: index.html:
It does work. Basically, the only thing that changed is that if I do a Does that make more sense? The reason I can't add a |
Can this issue please be re-opened? Adding to your paths is not an option for me either- |
we use requirejs to provide a kind of 'plugin' system, and it seriously makes everything complex, @jrburke could we hope that you reconsider ? adding a 'path' is not an option for us neither. |
When I 'require' a remote module using an absolute url (http://) path, and that module requires other modules relative to it, the resolved paths for these modules are also absolute but lack the ".js" extension thus they are not found.
Example:
And inside RemoteModule:
Require.js will load RemoteModule fine, but then will try to load OtherModule from the url http://other.domain/otherModule (without the extension) and fails with not-found error.
My use case is simply loading a remote module that has relative dependencies. What would be the correct way to do this?
The text was updated successfully, but these errors were encountered: