0

I have a working web app using require.js and I'm trying to have all files be minified and concatenated. I'm using grunt-contrib-requirejs to compile the whole project into a bundle.js file, like so:

    requirejs: {
        compile: {
            options: {
                baseUrl: "public/",
                mainConfigFile: "config.js",
                name: "start",
                out: "public/bundle.js",
                preserveLicenseComments: false,
            }
        }
    }

Now I've changed my index.html to call the bundle rather than the unbundled start.js entry point:

replaced: <script data-main="start" src="require.js"></script>

with: <script data-main="../bundle.js" src="require.js"></script>

Compilation seems to be doing fine, and bundle.js is indeed found, but I'm getting this error:

Uncaught SyntaxError: ../bundle.js: In strict mode code, functions can only be declared at top level or immediately within another function.

But the chrome debugger shows the error as thrown from require.js. I'm pretty sure there is no mistake in require.js. How can I find which part of my code produces the error?

update This may (or may not) be related to this recent jQuery bug. I can't tell because when I use the non-minified version of jquery, I get another error ("define is not defined") coming from this line: define("jquery", function(){});. I don't know where this line comes from either, it seems like a strange thing to do...

Shawn
  • 10,931
  • 18
  • 81
  • 126
  • It sounds like you have a function defined in a different block (e.g. an `if..else`) that is not the top `{}`s of another function or not wrapped at all. If this was intentional, you probably meant to write it as a function expression and not a function declaration. If the actual cause is in a framework you're using, congrats you've found a bug and should report it to that framework's developers – Paul S. Jul 26 '14 at 13:13
  • Yes, I understand what the error means. I'm just trying to find where in my code I made this mistake. If the error could provide the function name, for example, I could easily grep it, find the problem and fix it – Shawn Jul 26 '14 at 13:15
  • the easiest way to identify the culprit may be tedious, i.e. searching for `function` and looking where it's defined each time :( .. anyway, [**here** is some more info on the issue](http://speakingjs.com/es5/ch07.html#_functions_in_strict_mode) – Paul S. Jul 26 '14 at 13:17
  • I have 237 hits... Hopefully someone finds a better solution... – Shawn Jul 26 '14 at 13:19
  • Do you have fewer hits if you only search for "use strict"? – Andy Jul 26 '14 at 13:25
  • I don't have "use strict" anywhere. It seems to be added by require.js – Shawn Jul 26 '14 at 13:29
  • But I have fewer hits searching for "for ", "for(", "while ", "while(", "if " and "if(", and I can't find any function definitions within these (I know about this rule so this was to be expected). – Shawn Jul 26 '14 at 13:31

0 Answers0