5
votes

If I run the optimizer without the "namespace: 'foo'" flag everything works as expected. When I add "namespace: 'foo'" into the app.build.js I get this error:

GET: file:// (path to the project) /require-jquery/jquery-require-sample/webapp/jquery.js
main-built.js:main-built.js:1839

Uncaught Error: Script error http://requirejs.org/docs/errors.html#scripterror
main-built.js:163

I have looked around for a solution but there is little info on using RequireJS optimizer to export a single file, with jquery, and a namespace. Thanks!

I have put the RequireJS + jQuery sample project (with a modified app.build.js and the app.html) on github here.

({
    baseUrl: ".",
    out: 'main-built.js',
    //Comment out the optimize line if you want
    //the code minified by UglifyJS
    optimize: "none",

    paths: {
        "jquery": "require-jquery"
    },

    name: 'main',
    namespace: 'foo'
})
2

2 Answers

0
votes

Try removing the name parameter instead (unless you really need it).

0
votes

I know I'm late to the party here, but this thread is easy to find by just googling.

jquery has AMD detection in it. You are using namespaces for requirejs, and that causes some changes in all calls of define function.

This causes a change in jquery that just breaks it (or just the actual define code, but your namespaced call will not work anyway)

I'm currently fighting that issue. I see following options:

  1. use jQuery globally, like it's 2005
  2. hack require namespacing to understand AMD detection
  3. hack together a shim for jquery to make it work

I'm going to try the third option and report back if there's anything to report

[edit]

Namespacing works inside of the shim also :( it makes no sense, but it just does. As of now I don't have any idea how to make it work with shim and without any changes to jquery itself. If you wish to fiddle with jquery, there's a line near the end that tests if define is a function for defining AMD modules. Break this line (eg. by adding false &&) and you have a working shim.