knockout reference, which means that knockout validation expects that the knockout module is called “knockout”.
This isn’t really a problem, unless you’re adding knockout to an existing project where you’ve called the knockout module something else (says
ko) in the requirejs config. Since the config allows you to call modules whatever you want it seems a little strange that knockout validation would insist that you call the module knockout, it would’ve be fairly trivial to make the module name a configurable item.
Requirejs does provide a way round this in the configuration, in the form of the map configuration property. The main aim of map is to allow mapping different version of a library to the same module name in a specific context. For example if you have a module that relies on a specific older version of jQuery you can map the jquery module definition to the specific version for that module, while allowing all other modules within your application to use the newer version jquery, all without the need for any of the modules to worry about specifically having to reference the correct version of jquery. As a result of this it means we can map specific module names to other existing modules.
Here’s the config for knockout without the mapping:
I’ve defined knockout as “ko” because it’s fewer characters to type. Anyway here’s my config to get knockout validation working and to make sure it loads knockout correctly when it requires it:
Now every time knockout validation attempts to load the knockout module, require will know which module to load.