@vitejs/plugin-legacy is for).build.target is an input to the esbuild transformhasOwn isn't covered by esbuild's syntax transforms, so a polyfill is needed.@vitejs/plugin-legacy? While referenced in the issue you referred to, it's not clear whether you are using it. hasOwn.shim() didn't seem to monkeypatch the Object global is strange but it does need to be run first thing at the entry point.has-own@vitejs/plugin-legacy@vitejs/plugin-legacybuild.targethasOwnhasOwn.shim()has-own// file: test.js
const object1 = {
prop: 'exists',
};
console.log(Object.hasOwn(object1, 'prop'));
// Expected output: true
console.log(Object.hasOwn(object1, 'toString'));
// Expected output: false
console.log(Object.hasOwn(object1, 'undeclaredPropertyValue'));
// Expected output: false
console.log(object?.noprop);esbuild test.js --target=es2015,edge88,firefox78,chrome87,safari14"use strict";
const object1 = {
prop: "exists"
};
console.log(Object.hasOwn(object1, "prop"));
console.log(Object.hasOwn(object1, "toString"));
console.log(Object.hasOwn(object1, "undeclaredPropertyValue"));
console.log(object == null ? void 0 : object.noprop);<script>
"hasOwn"in Object||(Object.hasOwn=Object.call.bind(Object.hasOwnProperty));
</script>