question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ima is not a function when i trying to use ima plugin with webpack project

See original GitHub issue

Hi all, a have big problem with using this plugin in my project. Libs:

video.js: v7.1.0
videojs-ima: v1.5.1

Code:

import videojs from 'videojs';
import 'videojs-ima';

class TestIMA {
     constructor() {}
     test() {
          const player = videojs(document.querySelector('.videojs-test'));
          player.ready(() => {
               player.ima({
                    id: 'video_story_item',
                    adTagUrl: '...'
               });
          });
     }
}

const testIMA = new TestIMA();
testIMA.test();

And i’m getting error ima is not a function

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
chadladensackcommented, Aug 29, 2018

After many late night hours I as finally able to configure webpack to import the dang module and expose the init method of the ImaPlugin. It’s a shim that forces the module to call registerPlugin against a temp var that holds the ImaPlugin init function. The exports loader exposes the temp var as a module default so we can snag the init method and register the plugin against the proper videojs instance.

webpack.config

module: {
  rules: [
    {
      // omg, WHY!?!?!1!
      test: /videojs.ima.js$/,
      use: [
        {
          loader: 'imports-loader',
          options: {
            define: ">false",
            exports: ">false",
            holder: ">{name:null, init:null}",
            this: ">{videojs:{registerPlugin:(name,init) => {holder.name = name; holder.init = init;}}}",
          }
        },
        {loader: 'exports-loader', options: "holder"},
      ]
    },
  ]
}

my_code_file.js

import videojs from "video.js";
require('videojs-contrib-ads');

let ima = require('videojs-ima/dist/videojs.ima');
videojs.registerPlugin(ima.name, ima.init);

I believe the issue is how webpack isolates each module. If you perform a standard import of the videojs-ima plugin all appears to be okay but the videojs instance the plugin initializes against is different than the one you’re working on.

Dear hard working Google devs, for the love of god, export the ImaPlugin. It would be even cooler if you could update your bundle process to create a true ES6 module in the dist 😃

2reactions
Kiro705commented, Oct 22, 2019

Hi all,

It looks as though the issue has been resolved. Please see our import guide if you are using webpack for your app.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bundle videojs with videojs-ima plugin - Stack Overflow
I am trying (already few days) to achieve very simple task: build one javascript file that bundle all necessarily parts to play video...
Read more >
Videojs ads demo - Caritas Castellaneta
Defaults to false videojs-contrib-ads + ima VideoJS websites that are also using Ads. Past the shortcode in post, page, widget areas To publish...
Read more >
Watch and WatchOptions | webpack
Webpack can watch files and recompile whenever they change. This page explains how to enable this and a couple of tweaks you can...
Read more >
TypeScript - webpack
const path = require('path'); module.exports = { entry: './src/index.ts', module: { rules: [ { test: /\.tsx?$/, use: 'ts-loader', exclude: /node_modules/, }, ], } ......
Read more >
Step-by-Step: Video.js Plugin Generator
In this topic, you will learn how to use the video.js plugin generator to create and test plugins for the Brightcove Player.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found