amd-optimize icon indicating copy to clipboard operation
amd-optimize copied to clipboard

An error occurred when require text file

Open sarike opened this issue 9 years ago • 2 comments

Hi, Thanks for the cool plugin first. I met a problem when I use amd-optimize. My code is as follows:

define(function (require) {
    var userInfoTemplate = require('text!./templates/userinfo.tpl');
}

After building code is as follows:

define('admin/dashboard/templates/userinfo.tpl', [], function () {
    return 'Hello <%=name %>';
});
define('admin/dashboard/index', [
    'require',
    'exports',
    'module',
    'admin/dashboard/templates/userinfo.tpl'
], function (require) {
    var userInfoTpl = require('text!./templates/userinfo.tpl');
}

But the code after building can not be executed correctly.

require.js:166 Uncaught Error: Module name "text!admin/dashboard/templates/userinfo.tpl_unnormalized2" has not been loaded yet for context: _

If this line:

var userInfoTpl = require('text!./templates/userinfo.tpl');

can be converted to:

var userInfoTpl = require('admin/dashboard/templates/userinfo.tpl');

Then code will be executed correctly!

This is a bug? Or did I do something wrong?

sarike avatar Mar 29 '15 02:03 sarike

+1

jameslai avatar May 21 '15 02:05 jameslai

After doing a little research, line 35 of trace.coffee seems to be the culprit. It removes the text! portion of the module name, but doesn't do the same to the references to the module. Removing this line seems to solve the problem.

As a note, I did a small test using r.js and a simple use case - r.js does not remove text! from any of the module names.

However, the tests in this repo fail once that chance is made, so someone felt this was an important distinction. Would love to get some insight into what the purpose of this was before making a PR.

jameslai avatar May 21 '15 03:05 jameslai