Question

I've tried to deploy my Durandal based solution. But I'm getting the following error once deployed.

Uncaught ReferenceError: requirejs is not defined main.js:1
(anonymous function)

I explored the files that got deployed with the projects, and require was included in the solution/path. The files have been deployed along with them. All that is different between the development and production copy is that my java script files get compressed. My next step is to see if this is related to the issue in any way?

Update: I found the source of the problem to be the following:

<body>
    <div id="applicationHost">
        @Html.Partial("_splash")
    </div>

    @Scripts.Render("~/scripts/vendor")
    @if (HttpContext.Current.IsDebuggingEnabled)
    {
        <script type="text/javascript" src="~/App/durandal/amd/require.js" data-main="@Url.Content("~/App/main")"></script>
    }
    else
    {
        <script type="text/javascript" src="~/App/main.js"></script>
    }

</body>

If i remove the IsDebuggingEnabled check, and just leave the following it all works (obviously)

 <script type="text/javascript" src="~/App/durandal/amd/require.js" data-main="@Url.Content("~/App/main")"></script>

As far as I remember, I haven't touched this code (created on initial project setup by template). So should all be as is from the Durandal VSX template.

Any idea why require would be removed during a non debugging deployment? :/

Était-ce utile?

La solution

Durandal 1.2 comes with an optimizer.exe (http://durandaljs.com/documentation/Optimizing-On-Dot-Net/) that creates a optimized version main-built.js that has either Almond (default) or RequireJS bundled. The example above tries to load the source main.js that's why the error is thrown.

After running optimizer.exe successfully the code should be changed to this.

...
else
{
    <script type="text/javascript" src="~/App/main-built.js"></script>
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top