{"id":2101,"date":"2022-08-30T15:22:03","date_gmt":"2022-08-30T15:22:03","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/12\/26\/problem-about-r-js-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:22:03","modified_gmt":"2022-08-30T15:22:03","slug":"problem-about-r-js-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-r-js-collection-of-common-programming-errors\/","title":{"rendered":"problem about r.js-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/cb6c40f1350c41ac73e7e0c24aea5b93?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nLouis<br \/>\njavascript requirejs runtime-error bundling-and-minification r.js<br \/>\nI bundle all my JS assets into one minified uglified file via r.js (part of requirejs).If any unhandled errors occur on the browser, I use raygun (like Airbrake) to report it back to me. The only problem is the line number I get in my error message, refers to the bundled minified file. Which doesn&#8217;t help much.Is there a way to correctly map the line number of my single minified and uglified bundled asset, into the individual JS file with the correct line number?<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/5b5c1c8d2cd9e9b370e30c5a1d09fbce?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPeter<br \/>\nrequirejs amd js-amd r.js almond<br \/>\nIn my grunt.js file I&#8217;ve gotrequirejs: {dist: {options: {almond: true,wrap: true,modules: [{name: &#8216;main&#8217;}],mainConfigFile: &#8220;src\/js\/main.js&#8221;,baseUrl: &#8220;src\/js&#8221;,dir: &#8220;tmp\/js&#8221;,inlineText: true,preserveLicenseComments: false}} }Running grunt requirejs:dist populates the tmp\/js directory with some minified files &#8211; among others a big main.js file (everything seems to be bundled in this file as expected) &#8211; however when I want to include this file like so&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;tmp\/main.js<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/4e826bf3987d32933fd7359797c009bc?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAlexander Klimetschek<br \/>\nrequirejs r.js<br \/>\nI am trying to integrate the r.js optimizer on the server side (Apache Sling) and face one problem: when resolving modules it always looks them up under the output directory (dir), not from within the source directory (baseUrl or appDir), doesn&#8217;t find them and thus fails.\/project\/build.js({name: &#8220;modules\/main&#8221;,dir: &#8220;\/target&#8221;,baseUrl: &#8220;\/sources&#8221; })If you wonder, the root path \/ is inside the server&#8217;s JCR repository, not a file system. Also I simplified the example a bit (hopefully without conceal<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7c1ff10d3a5a1e5e8cf16f3d7a1c2f62?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nToddish<br \/>\nbackbone.js requirejs r.js<br \/>\nWhen I run the r.js optimizer over my Backbone.js app, I get this error:Uncaught TypeError: undefined is not a functionIt appears in the middle of the Backbone.js section of the output.I removed bits of code until I found out what was causing it, and it seems to be when I call Backbone.history.start();.I&#8217;ve created a simple app to replicate the bug, which I&#8217;ve posted below. Basically, it creates a route and &#8216;console.log&#8217;s &#8216;home&#8217;. It works fine when not optimized.To optimize the app, I use:node r<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f7ffa8a69bff0f4a013ab775752d2756?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nDJ Forth<br \/>\nrequirejs ruby-on-rails-4 r.js<br \/>\nI am using Require.js in a rails 4 application. However in the production environment I&#8217;d like to compile into 1 file and use almond. Now obviously require.js recommends r.js, which even has a coffeescript plugin for it, but would mean running it outside of rails manually. There is the requirejs-rails gem, but this seems to have not been updated for a while and doesn&#8217;t have rails4 support. There is a couple of forked version but I get an error when I try to use them:`user_config=&#8217;: undefined<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/57ed1491a844ed59227c11ed96386f9d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMrLipman<br \/>\nrequirejs js-amd uglifyjs r.js<br \/>\nI&#8217;m using r.js to optimize\/uglify my JavaScript code which is using RequireJS.One of my modules is a polyfill module:define(function(){if (!Array.prototype.filter){ \/* &#8230; *\/ }var isPolyfillNeeded = function () { \/* &#8230; *\/ }if (isPolyfillNeeded()) {\/* polyfill implementation *\/} });The module causes parsing error thrown from r.js when trying to uglify it, saying:Tracing dependencies for: ..\/scripts\/main-app Error: Parse error using UglifyJS for file: C:\/&#8230;\/polyfill.js Unexpected character &#8216;?&#8217;<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c2f58a337a2d264ce6e380794d63fb6e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nDan Ramos<br \/>\njavascript requirejs grunt r.js<br \/>\nI&#8217;m able to successfully compile my JS modules via Grunt&#8217;s requirejs task, but I&#8217;m getting undefined with any shim scripts. Here is my configrequirejs.config({&#8220;baseUrl&#8221;: &#8220;..\/..\/..\/components\/&#8221;,&#8221;paths&#8221;: {&#8220;less&#8221;: &#8220;less.js\/dist\/less-1.3.3&#8243;,&#8221;datepicker&#8221;: &#8220;jquery-ui\/ui\/jquery.ui.datepicker&#8221;,&#8221;jquery&#8221;: &#8220;jquery\/jquery&#8221;,&#8221;jqueryui&#8221;: &#8220;jquery-ui\/ui\/jquery-ui&#8221;,&#8221;spectrum&#8221;: &#8220;spectrum\/spectrum&#8221;,&#8221;class&#8221;: &#8220;class\/class&#8221;,&#8221;underscore&#8221;: &#8220;underscore-amd\/underscore&#8221;,&#8221;d3&#8243;: &#8220;d3\/d3&#8243;,&#8221;nv&#8221;: &#8220;nvd3\/nv.d3&#8243;,&#8221;dataTables&#8221;: &#8220;data<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fe7f2c030846844c6ffd78c8dc099f7e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nGeoff<br \/>\noptimization requirejs r.js<br \/>\nI might be missing something here (it could be a RTFM).I am trying to use the requirejs optimizer to optimize a file and require it. but the value always comes back undefined. I created the most simple test.My module (Models\/Test.js):define(function () {return &#8220;from module&#8221;; });My module after I run r.js: (Models\/Test-built.js):define(&#8216;MODELS\/Test&#8217;,[],function () {return &#8220;from module&#8221;; });When I include the original in a page:&lt;script&gt;require([&#8216;Models\/Test&#8217;], function (item) {console.log(i<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-12-26 03:14:31. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Louis javascript requirejs runtime-error bundling-and-minification r.js I bundle all my JS assets into one minified uglified file via r.js (part of requirejs).If any unhandled errors occur on the browser, I use raygun (like Airbrake) to report it back to me. The only problem is the line number I get in my error message, refers to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2101","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2101"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2101\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}