Open AlexDomeshek opened 11 years ago
That error can happen the following ways:
If you think it might be the second issue, to find the source of the problem, in the built files, look for define(
calls that do not have a string ID as the first argument. If that is in a particular library, then what you might also see in the build output is a "toTransport" warning saying that it skipped the file.
If you have the source or that module, feel free to point to it here, so it could be used for tests and any eventual fix.
I believe I'm seeing this issue when I include the main js-beautify library file:
build.js:
({
baseUrl: ".",
normalizeDirDefines: "all",
paths: {
'beautify': 'dependencies/beautify/js/lib/beautify',
...
},
name: "javascripts/console.js",
out: "javascripts/console-built.js"
})
Build run:
r.js -o build.js optimize=none
Build output:
Tracing dependencies for: javascripts/console.js
dependencies/beautify/js/lib/beautify.js has more than one anonymous define. May be a built file from another build system like, Ender. Skipping normalization.
PROJECT_PATH/javascripts/console-built.js
----------------
...
PROJECT_PATH/dependencies/beautify/js/lib/beautify.js
PROJECT_PATH/javascripts/console.js
Relevant output in console-built.js
for js-beautify:
...
if (typeof define === "function") {
// Add support for require.js
if (typeof define.amd === "undefined") {
define(function(require, exports, module) {
exports.js_beautify = js_beautify;
});
} else {
// if is AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
define([], function() {
return js_beautify;
});
}
} else if (typeof exports !== "undefined") {
// Add support for CommonJS. Just put this file somewhere on your require.paths
// and you will be able to `var js_beautify = require("beautify").js_beautify`.
exports.js_beautify = js_beautify;
} else if (typeof window !== "undefined") {
// If we're running a web page and don't have either of the above, add our one global
window.js_beautify = js_beautify;
} else if (typeof global !== "undefined") {
// If we don't even have window, try global.
global.js_beautify = js_beautify;
}
...
Yes, looks like js-beautify has two defines in there when only one is enough. The second one should work fine in all AMD loaders, so it is best to inform them of it. This will work with all AMD loaders, as requirejs is an AMD loader:
if (typeof define === "function" && define.amd) {
define([], function() {
return js_beautify;
});
}
Hi, all! I have successfully run r.js and unified all my java scripts under main.js. But I when I run the app with minified version of main.js I get a following exception: Mismatched anonymous define() module: Any ideas how to resolve this? Thanks in advance!
This is my build.js
({ appDir: ".", baseUrl: "src/main/webapp/js", dir: "../appdirectory-build", modules: [ { name: "main" } ], paths: {
})
This is my main.js
require.config({ baseUrl: "/js", paths: {
});
require(["app"], function(App) { App.initializeApplication()
});