Mimosa warns that RequireJS text loader dependency cannot be found #137

Closed
neverfox opened this Issue Feb 14, 2013 · 9 comments

3 participants

@neverfox

From assets/javascripts/main.coffee:

requirejs.config
  urlArgs: "b=#{(new Date()).getTime()}" 
  shim:
    "ember":
      deps: ["handlebars", "jquery"]
      exports: "Ember"
  paths:
    "App": "app/main"
    "views": "app/views"
    "controllers": "app/controllers"
    "templates": "app/templates"
    #libs
    "jquery": "vendor/jquery.min"
    "handlebars": "vendor/handlebars"
    "ember": "vendor/ember"
    "bootstrap": "vendor/bootstrap.min"
    #requirejs-plugins
    "text": "vendor/text"

require ["App", "ember"], (App, Ember) ->
  App = Ember.Application.create(App)

assets/javascripts/views/ApplicationView.js:

define([
    "ember",
    "text!templates/applicationTemplate.html"
], function(Ember, applicationTemplate) {

    var ApplicationView = Ember.View.extend({
        defaultTemplate: Ember.Handlebars.compile(applicationTemplate)
    });
    return ApplicationView;
});

assets/javascripts/templates/applicationTemplate.html:

<h1>Hello, World!</h1>

Configuration is pure default.

After running mimosa watch --server, I get this message:

Dependency [[ templates/applicationTemplate.html ]], inside file
[[ <disguised path>\public\javascripts\app\views\ApplicationView.js ]],
cannot be found.

However, the server starts up and when I visit localhost:3000, the template is rendering fine. Is this message occurring simply because Mimosa is unable to verify that text! paths are valid even though RequireJS can?

@dbashford
Owner

Yeah, that's just Mimosa doing path verification and failing in this case. It doesn't hurt anything.

Curious, if you change this:

    "text!templates/applicationTemplate.html"

to this

    "text!app/templates/applicationTemplate.html"

does Mimosa complain about that? It might just be that the mimosa-require module, after it pulls apart text and templates/applicationTemplate.html isn't doing the directory aliasing correctly with templates.

@neverfox

No, adding app/ stops the message.

@dbashford
Owner

Cool, that helps, I'll take a look.

@neverfox

Here's another interesting case: separating out your RequireJS configuration into a separate module. RequireJS has no problem with this; the app runs fine. But Mimosa currently warns you about every file that references one of the path dependencies, telling you that it cannot be found.

config.js

define({
    app_name: "MyExampleApp",
    urlArgs: "b=" + ((new Date()).getTime()),
    shim: {
        'ember': {
            deps: ['handlebars', 'jquery'],
            exports: 'Ember'
        },
        'jquery.ui': ['jquery']
    },
    paths: {
        'App': 'app/main',
        'models': 'app/models',
        'views': 'app/views',
        'controllers': 'app/controllers',
        'templates': 'app/templates',
        'routes': 'app/routes',
        /*libs*/
        'jquery': 'libs/jquery/1.9.0/jquery',
        'handlebars': 'libs/handlebars/1.0.rc.1/handlebars',
        'ember': 'libs/ember/1.0.0-pre.4/ember',
        'jquery.ui': 'libs/jquery.ui/1.9.2/jquery-ui-1.9.2.custom.min',
        'bootstrap': 'libs/bootstrap/2.2.2/js/boostrap',
        /*requirejs-plugins*/
        'text': 'libs/requirejs-plugins/text',
        'hbs': 'libs/requirejs-plugins/hbs',
        'domReady': 'libs/requirejs-plugins/domReady'
    },
    /*hbs plugin options*/
    hbs: {
        disableI18n: true,
        templateExtension: "html"
    }
});

main.js

(function(root){
    require(["config"], function(config){
        requirejs.config(config);
        require(["App", "ember"], function(App, Ember){
            var app_name = config.app_name || "App";
            root[app_name] = App = Ember.Application.create(App);
            App.deferUntilDOMReady();
        });
    });
})(this);
@dbashford
Owner

Yeah, this is a known thing and I should mention it in the docs somewhere. There's only so far I took the path checking. I could probably alter some things to figure this out, but it would be a pretty large effort. I'm literally eval-ing each piece of code after defining my own define/require/requirejs methods to detect require/define calls, which means calls nested inside callbacks are problematic. I do some regex-ing of callback code to find nested calls and do verification, but this case you've mentioned here would be real tricky. I'm all for ideas if you have them.

For now, if this is the route you are going to go with your requirejs config, I'd suggest turning off verification.

require:
  verify:
    enabled: false

The text plugin thing should be fixable, and when real life steps out of my path it'll be one of the first things I check out, though I know it might not mater to you know if you've got things configured this way.

@dbashford
Owner

Actually, idea occurred to me, think I got this when I get time

@dbashford dbashford added a commit to dbashford/mimosa-require that referenced this issue Feb 20, 2013
@dbashford fixes dbashford/mimosa#137, handling files with extensions properly w…
…hen aliased by directory, upgrading almond
4b4a379
@dbashford dbashford referenced this issue in dbashford/mimosa-require Feb 20, 2013
Closed

Handle common configs #9

@dbashford
Owner

So I've fixed the original issue. I've also pulled the follow-on issue you reported into its own issue in the mimosa-require repo.

@dbashford dbashford closed this Feb 20, 2013
@dbashford
Owner

Begun really working on handle common config. Have you had success building, with r.js the common configuration setup you have above? Specifically this:

config.js

define(...config object here...)

main.js

require(["config"], function(config){
  requirejs.config(config);
  require(["App", "ember"], function(App, Ember){
      ...
  });
});

I can get that working when dealing with a pre-built app, but r.js complains that it cannot find things that have been aliased using the path config. So, in the case above, it would attempt to look for baseUrl/App and not find it because it is located at baseUrl/app/main as indicated by the path config.

@jrburke, should this work? I am familiar with the setup you have here, but when @neverfox posted the above it was the first time I'd seen it done that way. Might I be screwing something up with the r.js config necessary to make this work?

Assuming it ought not work, it would be fairly trivial to change the above to...

reqirejs.config(...config object here...)

main.js

require(["config"], function(config){
  require(["App", "ember"], function(App, Ember){
    ...
  });
});
@jrburke

@dbashford it sounds like the build config needs to point to the 'config.js' file for mainConfigFile, but r.js only scans for requirejs.config() or require.config() calls in a mainConfigFile file, not define() calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment