Reputation: 1048
I am using Typescript with ESNEXT
(as of 2021) replaceAll
in my code, because it is clearer than using a regexp.
I am transpiling to es5
, but in the dist
folder, in the traspiled js code, replaceAll
remains as it is and there is a TypeError: replaceAll is not a function
error.
I thought that Typescript would have traspiled it to es5, in a way that it works with es5. Why does it not do it? How can I fix this problem?
My TS config is:
{
"compilerOptions": {
"strict": true,
"target": "es5",
"lib": [
"ES2021"
],
"sourceMap": true,
"outDir": "../dist/server",
"baseUrl": ".",
"resolveJsonModule": true,
"downlevelIteration": true,
"paths": {
"@/*": [
"./*"
]
}
}
}
Upvotes: 2
Views: 847
Reputation: 275867
TypeScript will transpile modern JS syntax to ES5 but not do the polyfilling (runtime apis).
You can use core-js for that. Add the following to your application entry point:
import 'core-js'; // <- at the top of your entry point
https://www.npmjs.com/package/core-js
Upvotes: 1