dotnet/AspNetCore.Docs · error · Error
ko.mapping.updateFromJS, use ko.mapping.fromJS instead. Plea
Error message
ko.mapping.updateFromJS, use ko.mapping.fromJS instead. Please note that the order of parameters is different!
What it means
knockout.mapping removed the old updateFromJS API and replaced it with a permanent stub that throws, directing callers to fromJS. The catch: fromJS takes parameters in a DIFFERENT order than updateFromJS did (data first, then optional target), so a blind rename silently corrupts mapping. The error message exists precisely to warn about the reordering.
Source
Thrown at aspnetcore/mvc/controllers/testing/samples/2.x/TestingControllersSample/src/TestingControllersSample/wwwroot/js/knockout.mapping.js:144
// Save any new mapping options in the view model, so that updateFromJS can use them later.
result[mappingProperty] = merge(result[mappingProperty], options);
return result;
} catch(e) {
mappingNesting = 0;
throw e;
}
};
exports.fromJSON = function (jsonString /*, options, target*/ ) {
var parsed = ko.utils.parseJson(jsonString);
arguments[0] = parsed;
return exports.fromJS.apply(this, arguments);
};
exports.updateFromJS = function (viewModel) {
throw new Error("ko.mapping.updateFromJS, use ko.mapping.fromJS instead. Please note that the order of parameters is different!");
};
exports.updateFromJSON = function (viewModel) {
throw new Error("ko.mapping.updateFromJSON, use ko.mapping.fromJSON instead. Please note that the order of parameters is different!");
};
exports.toJS = function (rootObject, options) {
if (!defaultOptions) exports.resetDefaultOptions();
if (arguments.length == 0) throw new Error("When calling ko.mapping.toJS, pass the object you want to convert.");
if (exports.getType(defaultOptions.ignore) !== "array") throw new Error("ko.mapping.defaultOptions().ignore should be an array.");
if (exports.getType(defaultOptions.include) !== "array") throw new Error("ko.mapping.defaultOptions().include should be an array.");
if (exports.getType(defaultOptions.copy) !== "array") throw new Error("ko.mapping.defaultOptions().copy should be an array.");
// Merge in the options used in fromJS
options = fillOptions(options, rootObject[mappingProperty]);
// We just unwrap everything at every level in the object graphView on GitHub (pinned to c67a80103a)
Solutions
- Replace ko.mapping.updateFromJS(viewModel, newData) with ko.mapping.fromJS(newData, viewModel) — note the swapped argument order.
- Update any in-place update: ko.mapping.fromJS(newData, {}, viewModel) if you also pass options.
- Search the codebase for all updateFromJS usages and migrate them together.
Example fix
// before ko.mapping.updateFromJS(viewModel, newData); // after (arguments swapped!) ko.mapping.fromJS(newData, viewModel);
Defensive patterns
Strategy: validation
Validate before calling
// Wrapper that maps the legacy updateFromJS call onto the new API with correct order.
function updateFromJSCompat(viewModel, newData) {
if (arguments.length < 2) {
throw new TypeError('updateFromJS(viewModel, newData) requires both args');
}
return ko.mapping.fromJS(newData, viewModel); // NOTE swapped order
} Type guard
function isMappedViewModel(vm) {
return vm != null && ko.isObservable(vm) && vm[mappingProperty] === true;
} Try / catch
// Prefer compile-time removal; this catch only aids migration diagnostics.
try {
ko.mapping.updateFromJS(viewModel, newData);
} catch (e) {
if (/use ko.mapping.fromJS instead/.test(e.message)) {
console.error('Deprecated API: rewrite as ko.mapping.fromJS(newData, viewModel)');
ko.mapping.fromJS(newData, viewModel);
} else { throw e; }
} Prevention
- Grep the codebase for updateFromJS/updateFromJSON during any knockout.mapping upgrade.
- Remember the argument order is SWAPPED in the new fromJS/fromJSON.
- Migrate all sibling calls at once and delete the wrapper once clean.
When it happens
Trigger: Calling ko.mapping.updateFromJS(viewModel, newData) left over from an older knockout.mapping version.
Common situations: Upgrading knockout.mapping from a pre-2.x plugin version; legacy codebases; copy-paste from old tutorials.
Related errors
- ko.mapping.updateFromJSON, use ko.mapping.fromJSON instead.
- When calling ko.fromJS, pass the object you want to convert.
- When calling ko.mapping.toJS, pass the object you want to co
- ko.mapping.defaultOptions().ignore should be an array.
- ko.mapping.defaultOptions().include should be an array.
AI-assisted analysis of dotnet/AspNetCore.Docs@c67a80103a (2026-08-13).
Data as JSON: /api/errors/e1b879249f3bdff3.
Report an issue: GitHub.