Looks like you need babel and webpack. These tools allow js and ts to be used together in both development and build.
.babelrc file (pay attention to @babel/preset-typescript):
{
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
],
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-transform-runtime"
]
}
and add something like this to webpack.config.js (pay attention to ts in rules/babel-loader):
module: {
rules: [
{
test: /\.(js|ts|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
],
}
require()is looking for .js file, not .ts. You should transpile typescript code to javascript if you really need to do this import.