Templates do not render when using Requirejs optimizer r.js

4 posts, 0 answers
  1. Negin
    Negin avatar
    15 posts
    Member since:
    Mar 2015

    Posted 21 Apr 2015 Link to this post

    Hi,

    We are trying to use a spa project template that Kendo put up on the Visual Studio Gallery https://visualstudiogallery.msdn.microsoft.com/924c3074-ceab-4be4-87e1-e9e4fd4b6d61 , The problem we are having is when building the requirejs app with the optimizer r.js, the app runs and no errors but the templates are not rendering, I can see that the templates have been included in the built file. The app and templates render no problem when not using the optimizer. 

    I have attached a project with the problem,

     

    Templates not rendering when using built file 

    <script src="@Url.Content("~/Scripts/require.js")" data-main="@Url.Content("~/App/main-built")"></script>

     

    Templates rendering with non built file

      <script src="@Url.Content("~/Scripts/require.js")" data-main="@Url.Content("~/App/main")"></script>

     

    Can anyone shed some light on this please?

     

    Thanks

    N.

  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 23 Apr 2015 Link to this post

    Hi Negin,

    Adding the following line seems to do the trick:

     <script src="@Url.Content("~/Scripts/require.js")" data-main="@Url.Content("~/App/main-built")"></script>
     <script>
           require("main");
     </script>


    Regards,
    Atanas Korchev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Negin
    Negin avatar
    15 posts
    Member since:
    Mar 2015

    Posted 23 Apr 2015 in reply to Atanas Korchev Link to this post

    Hi Atanas,

    When I add the extra script tag as you suggested

     <script>
           require("main");
     </script>

     

    I get the following error in the console.

     

    Error: Module name "main" has not been loaded yet for context: _. Use require([])
    http://requirejs.org/docs/errors.html#notloaded
    http://localhost:55661/Scripts/require.js
    Line 166

    Thanks

     N.

  5. Negin
    Negin avatar
    15 posts
    Member since:
    Mar 2015

    Posted 23 Apr 2015 in reply to Negin Link to this post

    Hey Atanas,

     

    I researched that error and I changed the code to this

         <script>
            require(['main'], function (main) {
                //main is now loaded.
            });
        </script>

     

    And everything now seems to work. :)

     

    Thanks

     

    N.

Back to Top
Kendo UI is VS 2017 Ready