1

I'm trying to use cast_receiver.js in my webpack v5 setup. Basically, I want to import the Google Cast classes like you would with any other import. Something like:

import cast from 'cast';
// or...
import cast from '//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js';

And then the resulting index.html should reference that exact url:

<head>
  <script src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
</head>

Reading the webpack docs, it seems this should be possible using externals. However, I'm not able to get this to work. I keep getting this error:

Cannot find module 'cast' or its corresponding type declarations.

Here is my webpack.config.ts:

externalsType: 'script',
  externals: {
    cast: [
      '//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js'
    ]
  },

Q: how can I import cast_receiver.js in my webpack configuration?

l33t
  • 18,692
  • 16
  • 103
  • 180

0 Answers0