-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RequireJS: "mismatched anonymous define()" error after r.js optmization #589
Comments
we would greatly welcome a PR around this that accommodates all major build systems/module types |
I have not used AMD in ages, but do you know of a way (if any) to declare optional dependencies with AMD @adambiggs? My initial hunch is to follow the first answer in this Stackoverflow post and define that
This is probably the best solution long-term but requires a lot of work. |
@adambiggs after talking some time to further understand this issue, I agree with your comment:
I will make the PR that reverts this and adds a section to our README for stubbing out jquery for webpack apps where it is not an explicit dependency. @TomiS after I revert the PR, you will have to go into the Webpack config file for your specific project and add something like the following to your resolve: {
alias: {
"jquery": path.join(__dirname, "./jquery-stub.js");
}
} Then in your project, you will have to create a module that exports a // Path: ./jquery-stub.js
module.exports = null; Your Webpack build should work fine (just verified this on a sample project). I will publish this as a major bump so that it is explicit that it is a breaking change |
@rovolution sorry for the slow response, I've been on vacation. Sounds like a good plan. Nice of you to test out the Webpack config for @TomiS too. Cheers! |
will be published to 8.0.0 |
Thanks @rovolution, the latest v9.0.0 now compiles without any issues using |
Nice to see a better solution for this. Works for our Webpack config too as expected. Thanks @rovolution and @adambiggs |
The change introduced by #580 seems to have broke this plugin when used with the RequireJS
r.js
optimizer.Prior to this change,
r.js
was able to parse the UMD wrapper correctly and give the anonymous module a name in the optimized file:But after #580 was merged, the
r.js
optimizer doesn't give the module a name, causingError: Mismatched anonymous define()
errors:The issue seems to be cause by wrapping the
define()
call in atry ... catch
. I confirmed this by installing the latest version (v7.1.1), manually removing the try/catch statement, and then running the result through ther.js
optimizer.The optimizer was then able to parse the UMD wrapper correctly again and give the anonymous module a name:
My suggestion would be to revert the #580 changes so that this module conforms to standard UMD.
I don't have any experience with Webpack, but I'm assuming the correct way to deal with #578 would be to use something like
resolve.alias
to definejquery
as a stub module.Another option might be to split this library into two modules - a "core" module without any dependencies, and a "jquery plugin" module that depends on the core module and
jquery
.The text was updated successfully, but these errors were encountered: