"weyland build" fails with "ko is not defined" in StarterKit (MVC Project Template) #254

Closed
RonaldV opened this Issue Aug 16, 2013 · 16 comments

Comments

Projects
None yet
4 participants

RonaldV commented Aug 16, 2013

Creating a fresh Durandal MVC Project and executing "weyland build" in the project directory fails with...

[Error: Error: The config in mainConfigFile C:/Users/ronald/Documents/Visual Studio 2012/Projects/Durandal2/Durandal2/build/App/main.js cannot be used because it cannot be evaluated correctly while running in the optimizer. Try only using a config that is also valid JSON, or do not use mainConfigFile and instead copy the config values needed into a build file or command line arguments given to the optimizer. Source error from parsing: C:/Users/ronald/Documents/Visual Studio 2012/Projects/Durandal2/Durandal2/build/App/main.js: ReferenceError: ko is not defined at Function.build.createConfig (C:\Users\ronald\AppData\Roaming\npm\node_modules\weyland\node_modules\requirejs\bin\r.js:24761:23)

Is there a knockout configuration missing from weyland config?

Owner

EisenbergEffect commented Aug 16, 2013

Hmm. Try deleting the mainConfigFile entry in the weyland-config file and
then run weyland build again. Let me know if that fixes it.

On Fri, Aug 16, 2013 at 5:53 AM, Ronald Verhaegen
notifications@github.comwrote:

Creating a fresh Durandal MVC Project and executing "weyland build" in the
project directory fails with...

[Error: Error: The config in mainConfigFile
C:/Users/ronald/Documents/Visual Studio
2012/Projects/Durandal2/Durandal2/build/App/main.js cannot be used because
it cannot be evaluated correctly while running in the optimizer. Try only
using a config that is also valid JSON, or do not use mainConfigFile and
instead copy the config values needed into a build file or command line
arguments given to the optimizer. Source error from parsing:
C:/Users/ronald/Documents/Visual Studio
2012/Projects/Durandal2/Durandal2/build/App/main.js: ReferenceError: ko is
not defined at Function.build.createConfig
(C:\Users\ronald\AppData\Roaming\npm\node_modules\weyland\node_modules\requirejs\bin\r.js:24761:23)

Is there a knockout configuration missing from weyland config?


Reply to this email directly or view it on GitHubhttps://github.com/BlueSpire/Durandal/issues/254
.

Rob Eisenberg,
President - Blue Spire
www.durandaljs.com

That resolved the same issue for me, thanks.

Owner

EisenbergEffect commented Aug 18, 2013

My apologies. The correct config went out in the raw html templates, but
not in the nugets. I'll do a point release in a couple of weeks and get
this fixed. Thanks for understanding.

On Sat, Aug 17, 2013 at 4:04 PM, Landon Bass notifications@github.comwrote:

That resolved the same issue for me, thanks.


Reply to this email directly or view it on GitHubhttps://github.com/BlueSpire/Durandal/issues/254#issuecomment-22818738
.

Rob Eisenberg,
President - Blue Spire
www.durandaljs.com

RonaldV commented Aug 19, 2013

Sorry for the late reply I was away for the weekend.
That fixed it for me also. No problem. Thanks for the great framework!

Contributor

tommck commented Aug 19, 2013

Are you guys somehow doing this as part of your build within VS.NET?

RonaldV commented Aug 19, 2013

Yes, I'm doing this as a Post-build event when building in release.
If you're wondering how...

if '$(Configuration)'=='Release' (
cd $(ProjectDir)
weyland build
)

I am doing it the same way RonaldV is. I previously used the optimizer executable as part of the build but I switched to weyland when I upgraded Durandal.

Owner

EisenbergEffect commented Aug 19, 2013

If either of you wants to write up a little markdown file with step-by-step
instructions on how to configure this in VS, I'd love to add it to our
official docs for other developers to benefit from.

On Mon, Aug 19, 2013 at 10:42 AM, Landon Bass notifications@github.comwrote:

I am doing it the same way RonaldV is. I previously used the optimizer
executable as part of the build but I switched to weyland when I upgraded
Durandal.


Reply to this email directly or view it on GitHubhttps://github.com/BlueSpire/Durandal/issues/254#issuecomment-22876829
.

Rob Eisenberg,
President - Blue Spire
www.durandaljs.com

Contributor

tommck commented Aug 19, 2013

That would be nice. As a non-node user, it would be nice to see how it's all done.. I assume node is somehow installed globally or something?

Here you go, hopefully your doc platform understands atx headers since it doesn't appear github does...

##Automating Builds with Visual Studio

###Prerequisites

###Add A Config File

  • At the project root create a js file named weyland-config.js
  • You can use the config file from the sample downloads as is, except remove this line or your build will fail:
    mainConfigFile: 'App/main.js',

###Add the Post Build Events

  • Go to the project's properties
  • Select Build Events
  • In the post build event add the following:

cd $(ProjectDir) weyland build

If you ony want to build when the Release configuration is selected, use the following:
if '$(Configuration)'=='Release' ( cd $(ProjectDir) weyland build )

Build your project, you should see the weyland build output in the Output window, with the last line similar to: "Optimized build created at ...App\main-built.js
###Include Generated Files in Project

  • In the solution explorer, select "Show All Files"
  • Under the App folder, locate main-built.js
  • Right click and select 'Include in Project'

###Auto Load Correct Files
Based on the Hot Towel SPA template, you can use the following code in your views/layouts to automatically load the correct file (main.js vs. main-built.js)
@if (HttpContext.Current.IsDebuggingEnabled) { <script type="text/javascript" src="~/Scripts/require.js" data-main="@Url.Content("~/App/main")"></script> } else { <script type="text/javascript" src="~/App/main-built.js"></script> }

Owner

EisenbergEffect commented Aug 19, 2013

Awesome. That will be just fine. It will go out in the site update this
week.

On Mon, Aug 19, 2013 at 3:20 PM, Landon Bass notifications@github.comwrote:

Here you go, hopefully your doc platform understands atx headers since it
doesn't appear github does...

##Automating Builds with Visual Studio

###Prerequisites

###Add A Config File

  • At the project root create a js file named weyland-config.js
  • You can use the config file from the sample downloads as is, except
    remove this line or your build will fail: mainConfigFile:
    'App/main.js',

###Add the Post Build Events

  • Go to the project's properties
  • Select Build Events
  • In the post build event add the following:

cd $(ProjectDir)
weyland build

If you ony want to build when the Release configuration is selected, use
the following:

if '$(Configuration)'=='Release' (
cd $(ProjectDir)
weyland build
)

Build your project, you should see the weyland build output in the Output
window, with the last line similar to: "Optimized build created at
...App\main-built.js
###Include Generated Files in Project

  • In the solution explorer, select "Show All Files"
  • Under the App folder, locate main-built.js
  • Right click and select 'Include in Project'

###Auto Load Correct Files
Based on the Hot Towel SPA template, you can use the following code in
your views/layouts to automatically load the correct file (main.js vs.
main-built.js)
@if (HttpContext.Current.IsDebuggingEnabled)
{

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

}
else
{

<script type="text/javascript" src="~/App/main-built.js"></script>

}


Reply to this email directly or view it on GitHubhttps://github.com/BlueSpire/Durandal/issues/254#issuecomment-22897324
.

Rob Eisenberg,
President - Blue Spire
www.durandaljs.com

RonaldV commented Aug 20, 2013

Well you beat me to it. Nice work landonbass.

Owner

EisenbergEffect commented Aug 20, 2013

I've added the docs to my site source, which will get published later this week. I'll also be publishing 2.0.1 in the next week or so to fix the config file problem and a few other bugs.

Contributor

tommck commented Aug 22, 2013

It looks like weyland is duplicating the requirejs configuration in it. Can we not just use the same require configuration we already use? I am using an external JS file for the config already. Is it possible for me to use that instead of the "paths" variable in there?

Owner

EisenbergEffect commented Aug 22, 2013

You can just set mainConfigFile to point to that as part of the rjs section
of the build task. But, it may not work right in the current version of
Weyland because it relies on that information to properly create the
include files list for the actual rjs config. Give it a shot...but no
guarantees. If you want to support that scenario, submit an issue to the
weyland project and please include your desired weyland config as well as
your external require config file.

On Thu, Aug 22, 2013 at 8:38 AM, Tom McKearney notifications@github.comwrote:

It looks like weyland is duplicating the requirejs configuration in it.
Can we not just use the same require configuration we already use? I am
using an external JS file for the config already. Is it possible for me to
use that instead of the "paths" variable in there?


Reply to this email directly or view it on GitHubhttps://github.com/BlueSpire/Durandal/issues/254#issuecomment-23086744
.

Rob Eisenberg,
President - Blue Spire
www.durandaljs.com

Owner

EisenbergEffect commented Aug 23, 2013

Removed the mainConfigFile part of the default weyland-config from the Durandal nuget. Also, updated the docs with the above. The config change was made in the Version-2.0.1 branch. The docs update will go out shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment