A 3rd party has provided me with a minified Javascript file that I need to use in my React 18.3.1 + Typescript 5.4.5 + Vite 5.2.12 project. I need to import their file in one of my components and invoke some functions that it contains. Their file is not a module, it does not have any export statements and they will not provide type definitions. Please see below for what their file looks like, how I try to import it and what error I am getting.
other-party-sdk.js (snippets from beginning and end, not the full file)
(function(_0x4b41bc,_0x1040a6){const _0x2f9107=a0_0x5ae2,_0x36e1b2=_0x4b41bc();while(!![]){try{const _0x3b1764=parseInt(_0x2f9107(0x39f))/0x1+-parseInt(_0x2f9107(0x5ee))/0x2+parseInt(_0x2f9107(0x120))/0x3*(parseInt(_0x2f9107(0x19a))/0x4)+parseInt(_0x2f9107(0x581))/0x5+-parseInt(_0x2f9107(0x4ef))/0x6*(-parseInt(_0x2f9107(0x1d1))/0x7)+-parseInt(_0x2f9107(0x46c))/0x8+parseInt(_0x2f9107(0xdb))/0x9*(-parseInt(_0x2f9107(0x4c8))/0xa);if(_0x3b1764===_0x1040a6)break;else _0x36e1b2['push'](_0x36e1b2['shift']());}catch(_0x11e9bf){_0x36e1b2['push'](_0x36e1b2['shift']());}}}(a0_0x51e4,0xbe510),
...
a0_0x51e4=function(){return _0x4c8758;};return a0_0x51e4();}
MyComponent.tsx (where I am trying to import and getting the error)
import * as otherPartySDK from '../../other-party-sdk';
//import * as otherPartySDK from '../../other-party-sdk.js';
function MyComponent() {
const stopAutoCapture = _ => {
otherPartySDK.cmd('...');
};
const startAutoCapture = e => {
otherPartySDK.on('...', result => {
//...
});
}
return <>Testing</>;
};
export default MyComponent;
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": false,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": [
"DOM",
"DOM.Iterable",
"ESNext",
],
"types": ["node", "vite-plugin-svgr/client"],
"module": "ESNext",
"moduleResolution": "Node",
"noEmit": true,
"noImplicitAny": false,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "ESNext",
"useDefineForClassFields": true
},
"include": [
"src"
],
"references": [
{
"path": "./tsconfig.node.json"
}
]
}
Error: File ‘../MyProject/src/other-party-sdk.js’ is not a module. ts(2306) [Ln 1, Col 34]
The only suggestions I have seen are to add exports in the JS file (it is not my file, comes from 3rd party) or allow JS in tsconfig.json (I already do). Thanks in advance for any tips to resolve this issue.