3

I hope my question doesn't seem silly, but I'm facing some issues when importing Shaka player in a typescript module like this:

import shaka from 'shaka-player/dist/shaka-player.ui';

In this case the compiler tells me this:

TS2306: File '~/dist/shaka-player.ui.d.ts' is not a module.

When looking at module architecture, you can obviously see in the dist folder contains currently the types declaration file and the js build for the module

enter image description here

And this is my tsconfig compiler options:

  "compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"allowJs": true,
"checkJs": false,
"types": [
  "webpack-env",
  "jest"
],
"paths": {
  "@/*": [
    "src/*"
  ]
},
"lib": [
  "esnext",
  "dom",
  "dom.iterable",
  "scripthost"
]

}

1 Answers1

0

Shaka is not a Typescript-native project, and the tools they are using to generate the definitions are clearly not able to do everything we need. But there is a solution, it depends on shaka-player version.

For v3: Create a global.d.ts file and declare

declare module 'shaka-player' {
  export = shaka;
}

For v4 and higher:

deleting all the .d.ts of the package 
rm ./node_modules/shaka-player/dist/*.d.ts

and then add to global.d.ts:

declare module 'shaka-player/dist/shaka-player.compiled' {
  export = shaka;
}

and make import:

 import shaka from 'shaka-player/dist/shaka-player.compiled';

Maybe they will add better support in future versions. But now, seems this is the only way...