Suppress error "Mismatched anonymous define()"#1354
Suppress error "Mismatched anonymous define()"#1354devote wants to merge 2 commits intorequirejs:masterfrom
Conversation
|
No plans to suppress this error since it is an indication of a larger problem with setup with the loader: for the resources to be useful in the loader, they should either be loaded with the loader or be built scripts with names in them. I agree that it is annoying, but suppressing the error will lead to harder to debug issues around project setup that will likely generate support requests and given the subtle nature of the issue will make it hard to provide timely support about it. |
Not many fewer questions arise about: "Mismatched anonymous define ()" But because of the lack of such a possibility, to have to write such a horrible code: (function(factory) {
if (typeof define === 'function' && define['amd']) {
var rndKey = '[library' + (new Date()).getTime() + ']';
var onError = requirejs['onError'];
factory.toString = function() {
return rndKey;
};
requirejs['onError'] = function(err) {
if (err.message.indexOf(rndKey) === -1) {
onError.call(requirejs, err);
}
};
define([], factory);
} else {
factory();
}
})(function() {
// library code here
return window.exportObject = exportObject;
});Do you think such an option you think would be better? |
|
What is the higher level goal you want to accomplish? Is it using the registered 'jquery' module by a different name? |
|
There is a library https://github.com/devote/HTML5-History-API. Allowed to execute code library in different ways. For example: Connect using SCRIPT tag: <script src="history.js"></script>or connecting via requirejs: <script src="require.js"></script>
<script>
require(['/history'], function(history) {
// ...
});
</script>the above two methods work fine, but if you connect as follows: <script src="require.js"></script>
<script src="history.js"></script>An error will occur: "Mismatched anonymous define()" This problem has forced me to write the code that I gave you in my previous comments. |
|
For the last one, if you want to use manual script tags, place it before the require.js tag: <script src="history.js"></script>
<script src="require.js"></script>Otherwise, the idea with the module system, if you want to use history.js to be loaded as a module, the |
I understand. I am writing here is not because I am struggling with this. That's because the others are constantly faced with this. And ask me questions on this issue. |
This fix allows you to suppress error "Mismatched anonymous define ()"
It is often necessary to determine the independent modules, for example such as "jQuery". What would be a possibility to declare the module without tying it tightly to a single name.
it is not flexible:
It is also as above, but more flexibly:
For example, if you create a library:
mylib.js: