Current Behavior
I am building an NPM package for Node using the 'basic' template. I tried using Object.fromEntries in my code but get the error:
TypeError: Object.fromEntries is not a function
Upon inspecting the .cjs.development.js output it leaves Object.fromEntries untransformed which I guess are not supported in Node 10. I tried using build --target node which does not resolve it. Changing target on tsconfig also does not fix this.
Expected behavior
Typescript or Babel should be able to compile Object.fromEntries
Suggested solution(s)
Maybe a Babel plugin or polyfill is missing.
Additional context
Following is code snippet and transformed output
Code:
export default class Platform {
id: string;
name: string;
channelLabelVsIdMap: Record<string, number>;
features: Record<string, Feature | undefined>;
constructor(platform: TPlatformMetadata, metadata: TMetadataResponse) {
const { features = [] } = metadata;
this.id = platform.id;
this.name = platform.name;
this.channelLabelVsIdMap = platform.channelLabelVsIdMap;
this.features = Object.fromEntries(
features
.filter((feature) => feature.platformId === platform.id)
.map((feature) => [feature.id, new Feature(feature, metadata)]),
);
}
}
Transformed output tsdx build
var Platform = function Platform(platform, metadata) {
var _metadata$features = metadata.features,
features = _metadata$features === void 0 ? [] : _metadata$features;
this.id = platform.id;
this.name = platform.name;
this.channelLabelVsIdMap = platform.channelLabelVsIdMap;
this.features = Object.fromEntries(features.filter(function (feature) {
return feature.platformId === platform.id;
}).map(function (feature) {
return [feature.id, new Feature(feature, metadata)];
}));
};
Your environment
System:
OS: macOS 10.15.3
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Memory: 792.30 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 10.22.0 - ~/.nvm/versions/node/v10.22.0/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.6 - ~/.nvm/versions/node/v10.22.0/bin/npm
Browsers:
Chrome: 88.0.4324.96
Firefox: 84.0.2
Safari: 13.0.5
npmPackages:
tsdx: ^0.14.1 => 0.14.1
typescript: ^4.1.3 => 4.1.3
Current Behavior
I am building an NPM package for Node using the 'basic' template. I tried using
Object.fromEntriesin my code but get the error:Upon inspecting the
.cjs.development.jsoutput it leavesObject.fromEntriesuntransformed which I guess are not supported in Node 10. I tried usingbuild --target nodewhich does not resolve it. Changingtargetontsconfigalso does not fix this.Expected behavior
Typescript or Babel should be able to compile
Object.fromEntriesSuggested solution(s)
Maybe a Babel plugin or polyfill is missing.
Additional context
Following is code snippet and transformed output
Code:
Transformed output
tsdx buildYour environment