In my project, there is a hypothetical Typescript file that I am working with (simplified example).
Utils.ts:
import * as HelperFromNodeModules from 'helper-from-node-modules';
class Utils {
static foo() {
return HelperFromNodeModules.parse(...);
}
}
The helper-from-node-modules
import includes a Javascript file.
helper-from-node-modules.js:
const dep = require('foo');
function parse(...) {
return bar.map((e) => {...});
}
Also included is the index.d.ts from @types/helper-from-node-modules
:
export function parse(...);
Within the tsconfig.json
, specifically look at:
{
...
"target": "es5",
"lib": ["es2015.collection","es6", "dom"],
"sourceMap": true,
"allowJs": true,
...
}
The issue arises when the Typescript compiler combines my compiled source code with all dependencies, resulting in es6 artifacts in the output file even though it should be strictly es5. This causes errors when expecting only es5 javascript.
Is there a way to instruct the Typescript compiler/transpiler to output es5 for javascript dependencies as well?
Additional Info:
Originally, I used react-create-app-typescript
and react-scripts-ts
as the boilerplate for my React app. The built-in webpack stack has strong opinions on where source code should come from and requires the compiled source to be es5. Any attempt to minify es6 artifacts will cause the minifier/uglifier to crash. Although I can modify the configurations by running npm run-script eject
, I prefer to avoid that route and compile the source to es6 without altering their webpack setup.