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.js throws this error unconditionally when the deprecated `ko.mapping.updateFromJS` is invoked. The function exists only to redirect callers to the replacement `ko.mapping.fromJS`. Unlike fromJS (jsObject, options, target), updateFromJS took (viewModel, ...) so the parameter order differs and silently swapping would corrupt mappings.
Source
Thrown at aspnetcore/mvc/controllers/testing/samples/3.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, data)` with `ko.mapping.fromJS(data, {}, viewModel)` — pass the JS object first, options second, and the existing viewModel as the target to update in place.
- Grep the codebase for `updateFromJS` to find every stale call site and migrate each.
- Pin knockout.mapping to a legacy version only if a full migration is impossible; otherwise finish the rename.
Example fix
// before
ko.mapping.updateFromJS(viewModel, data);
// after
ko.mapping.fromJS(data, {}, viewModel); Defensive patterns
Strategy: validation
Validate before calling
// Before calling, confirm the legacy API is not used:
if (typeof ko.mapping.updateFromJS === 'function') {
console.warn('updateFromJS is a stub that throws — migrate to ko.mapping.fromJS');
}
// Then call the supported API:
ko.mapping.fromJS(data, {}, viewModel); Type guard
function isSupportedMapping(fn) {
return fn !== ko.mapping.updateFromJS && fn !== ko.mapping.updateFromJSON;
} Try / catch
// Not recommended — these stubs always throw. Migrate instead.
try { ko.mapping.updateFromJS(viewModel, data); }
catch (e) { console.error('Migrate to ko.mapping.fromJS:', e.message); } Prevention
- Search the codebase for updateFromJS/updateFromJSON whenever bumping knockout.mapping.
- Keep a single helper that wraps fromJS/fromJSON so call sites never reach the legacy stubs.
- Add an ESLint no-restricted-syntax rule banning ko.mapping.updateFrom*.
When it happens
Trigger: Calling `ko.mapping.updateFromJS(viewModel, data)` — any call site still using the legacy update-from-JavaScript-object API. The throw is the entire function body, so even a valid invocation fails.
Common situations: Upgrading knockout.mapping from an older version that shipped updateFromJS; copy-pasted code from pre-2.0 tutorials; large legacy codebases where the rename was missed during a dependency bump.
Related errors
- ko.mapping.updateFromJSON, use ko.mapping.fromJSON instead.
- 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.
- There already is an object with the key that you specified.
AI-assisted analysis of dotnet/AspNetCore.Docs@c67a80103a (2026-08-13).
Data as JSON: /api/errors/48a178ff56da5512.
Report an issue: GitHub.