You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mainConfigFile not resolving paths defined in deps. #406
I have an issue that may very well just be beyond the scope of r.js, however I figured I'd ask just in case.
The basic problem is that I have a config defined in mainConfigFile. This config pulls in additional configs and the main app code via deps. The reason I'm having to use this oddly nested, "config loading configs" structure is because I'm using a build tool that automatically generates a require.config (similar to how JamJS does it).
This structure works just fine in the browser however r.js barfs, presumably because the require.config() method isn't actually called but I'm not sure.
I've put together a (contrived) testcase which you can find in this gist.
On first look, it seems like mainConfigFile should point to app/vendor/config.js, but if you need both configs loaded, then you are better off constructing a program in node to pull out the configs and merging them if you cannot get by with just the one and do not want to copy/paste one of them into the build config.
Closing as part of bug triage, but feel free to continue discussion here and can reopen later if an issue is discovered.
The app/config also has some configuration details (paths, shims, and configs, specifically) independent from those defined in app/vendor/config (which are programmatically generated by this build tool).
The decisions which lead me to this point were that the vendor stuff should be versioned yet easily updated. The application should assume vendor libraries are defined but shouldn't worry about resolving the vendor paths or anything. Thus, the build tool generates a require.config specifically for the vendor libraries which the application digests while maintaining it's own config.
I can definitely have the build tool merge the two, this just felt like a way to keep the two more isolated.
That all said, I could very well be approaching this in the wrong way (it's been a long day); am I over-thinking it? Is there a more simple solution I'm overstepping?
Also, part of the reason this feels more like an issue is because I can specify config data (as in module.config()) inside one of those nested configs, and those objects are available.
In this case, module.config().val appropriately resolves to ohboy inside library.js (assuming the path for library.js is resolved implicitly).
edit: I should clarify, I understand why that happens (module.config() being called in the application code, while paths need to be resolved as part of the build step), I just wish the paths could be used as well.
This has come up in different forms before, where some folks have two blocks of config. What I can look at for 2.2.0 is allowing an array value for mainConfigFile, to allow specifying multiple files to scan for config calls.
After we spoke initially, I went ahead and wrote a task to merge the configs in the meantime.
One thing I noticed (and let me know if you'd like me to open a separate issue for this) while playing around a bit is that load order can be significant when using the deps property with multiple files containing require.config statements. E.g.,
This works in the browser. My build task merges lib/config.js with my build config (where mainConfigFile points to config.js) but then fails to take into account selectors.js. If, however, I swap the order of the deps in config.js to:
Then I can use module.config().selector in example.js.
I know this is a miserably contrived example and that I'm clearly doing things in a way you'd never intended but figured I'd mention it just in case. Also, I try to avoid filing an issue without a PR so I'd be happy to give it an attempt when things calm down over here.
Yes, the order is important, and would be mentioned as part of any array support for mainConfigFile. The rule will basically be: configs are applied in order of the mainConfigFile array, so the last one would win in any conflict. Also note that explicit build config wins over mainConfigFile array, and command line r.js args win over anything else.
@jrburke:
I'm facing the same problem as the issue holder, I guess. Though my setup is a bit simpler.
r.js and RequireJS seem to ignore my paths configuration.
The reason why I'm exporting the config is, that I'm using it with RequireJs (in Node-Context) in a Grunt task. So actually the config is used at three points: the browser (for development), r.js (to build one .js file) and the Grunt task (to process things offline using the models and collections).
(I've tried almond: true without name and include as I thought it's the shorthand for a single-app. I further removed the optimizer stuff as I wanted to exclude that this is causing it.)
Error Output:
Options: logLevel=0, done=undefined, baseUrl="./src/js/", mainConfigFile="./src/js/main.js", name="../libs/almond", include="main", findNestedDependencies, out="target/main.js"
>> Tracing dependencies for: ../libs/almond
>> Error: ENOENT, no such file or directory
>> '/home/XXXXXX/XXXXXX/gallery/src/js/jquery.js'
>> In module tree:
>> main
As you can see, r.js/RequireJs is looking up jquery at the wrong place not respecting the paths config.
I'll update this issue these days giving more details (and hopefully a improvement to r.js).
Short: mainConfigFile wont recognize configurations when passed as previously declared variable.
I'm working on a r.js improvement to support this case. (Don't hesitate to ask me if I do not react the next days. ;)
@is-already-taken Did you finalize a solution to this problem? I also have 2 requirejs.config calls in a single file, but only the first is being read.
Activity
jrburke commentedon Mar 15, 2013
On first look, it seems like mainConfigFile should point to app/vendor/config.js, but if you need both configs loaded, then you are better off constructing a program in node to pull out the configs and merging them if you cannot get by with just the one and do not want to copy/paste one of them into the build config.
Closing as part of bug triage, but feel free to continue discussion here and can reopen later if an issue is discovered.
jasisk commentedon Mar 15, 2013
I knew I'd left something out of my example.
The app/config also has some configuration details (
paths,shims, andconfigs, specifically) independent from those defined in app/vendor/config (which are programmatically generated by this build tool).The decisions which lead me to this point were that the vendor stuff should be versioned yet easily updated. The application should assume vendor libraries are defined but shouldn't worry about resolving the vendor paths or anything. Thus, the build tool generates a require.config specifically for the vendor libraries which the application digests while maintaining it's own config.
I can definitely have the build tool merge the two, this just felt like a way to keep the two more isolated.
That all said, I could very well be approaching this in the wrong way (it's been a long day); am I over-thinking it? Is there a more simple solution I'm overstepping?
jasisk commentedon Mar 15, 2013
Also, part of the reason this feels more like an issue is because I can specify
configdata (as inmodule.config()) inside one of those nested configs, and those objects are available.e.g.,
In this case,
module.config().valappropriately resolves toohboyinsidelibrary.js(assuming the path forlibrary.jsis resolved implicitly).edit: I should clarify, I understand why that happens (
module.config()being called in the application code, while paths need to be resolved as part of the build step), I just wish the paths could be used as well.jrburke commentedon Mar 20, 2013
This has come up in different forms before, where some folks have two blocks of config. What I can look at for 2.2.0 is allowing an array value for mainConfigFile, to allow specifying multiple files to scan for config calls.
jasisk commentedon Mar 20, 2013
Thanks for the reply.
After we spoke initially, I went ahead and wrote a task to merge the configs in the meantime.
One thing I noticed (and let me know if you'd like me to open a separate issue for this) while playing around a bit is that load order can be significant when using the
depsproperty with multiple files containingrequire.configstatements. E.g.,This works in the browser. My build task merges
lib/config.jswith my build config (wheremainConfigFilepoints toconfig.js) but then fails to take into accountselectors.js. If, however, I swap the order of the deps inconfig.jsto:Then I can use
module.config().selectorinexample.js.I know this is a miserably contrived example and that I'm clearly doing things in a way you'd never intended but figured I'd mention it just in case. Also, I try to avoid filing an issue without a PR so I'd be happy to give it an attempt when things calm down over here.
jrburke commentedon Mar 20, 2013
Yes, the order is important, and would be mentioned as part of any array support for mainConfigFile. The rule will basically be: configs are applied in order of the mainConfigFile array, so the last one would win in any conflict. Also note that explicit build config wins over mainConfigFile array, and command line r.js args win over anything else.
KidkArolis commentedon Jul 2, 2013
+1 on mainConfigFile array.
Exactly for the reasons stated above, would be useful for keeping the manually editable config separate from the generated config.
is-already-taken commentedon Apr 22, 2014
@jrburke:
I'm facing the same problem as the issue holder, I guess. Though my setup is a bit simpler.
r.js and RequireJS seem to ignore my paths configuration.
Tree fragment:
The libaries have version suffixes (except almond.js).
main.js fragment:
The reason why I'm exporting the config is, that I'm using it with RequireJs (in Node-Context) in a Grunt task. So actually the config is used at three points: the browser (for development), r.js (to build one .js file) and the Grunt task (to process things offline using the models and collections).
Gruntfile fragment:
(I've tried
almond: truewithoutnameandincludeas I thought it's the shorthand for a single-app. I further removed the optimizer stuff as I wanted to exclude that this is causing it.)Error Output:
As you can see, r.js/RequireJs is looking up jquery at the wrong place not respecting the
pathsconfig.I also looked at these questions:
Some of them have solutions (that I followed or just tried with out luck) some have no solution.
is-already-taken commentedon Apr 23, 2014
OK, after debugging r.js I found the problem.
I'll update this issue these days giving more details (and hopefully a improvement to r.js).
Short:
mainConfigFilewont recognize configurations when passed as previously declared variable.I'm working on a r.js improvement to support this case. (Don't hesitate to ask me if I do not react the next days. ;)
brewern commentedon Nov 27, 2014
@is-already-taken Did you finalize a solution to this problem? I also have 2 requirejs.config calls in a single file, but only the first is being read.
andrey-buligin commentedon Apr 1, 2015
Any updates?