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.

Adding CDN player.js to a page which already has require.js on it will fail

See original GitHub issue

Expected Behavior

player.js is instantiated without any problems and videos play happily.

Actual Behavior

The define functions clash with the already instantiated RequireJS.

Steps to Reproduce

  1. Load a copy of RequireJS. Having it actual resolve dependencies is unnecessary for issue reproduction.
  2. Later, include the CDN link to player.js in a script tag. This is done by a number of external libraries.
  3. The summoned video will not play.

I have a quickly knocked-together pen: http://codepen.io/jodi/pen/qqbXxw

Apologies for all the script tags, it’s just for easy toggling so you can see the effects each setting/script has.

My suggestion is to provide either a separate player.iife.js or something for including via a script tag. Alternatively, maybe provide the iife version by default. Maybe I don’t have enough knowledge, but I don’t think the user would need the AMD or CommonJS module syntaxes when accessing it via a CDN.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
JodiWarrencommented, Nov 29, 2016

@bdougherty Not to my knowledge. UMD makes sense in most circumstances. I’m sure there’s a better solution than what I’ve proposed, but I couldn’t find one.

I’ve now had to fix a few Magento 2 sites which had included player.js via the CDN, so I’m assuming there are more of them out there too. My method has been to generate a custom build of player.js with the Rollup format option set to iife and use that instead.

Perhaps just a note in the documentation suggesting doing the above would suffice!

1reaction
BB-000commented, Oct 3, 2018

Still struggling to get this to work with require.js & Magento 2…

Uncaught TypeError: Vimeo.Player is not a constructor

requirejs-config.js:

var config = {
  map: {
    '*': {
      'vimeo': 'js/vendor/vimeo',
    }
  }
};

js file:

require(['jquery', 'vimeo'], function ($, Vimeo) {
    player1 = new Vimeo.Player('vid-1', { id: 0101010 });
    player1.play();
});

Seems correct to me. Do I need to change the player.js file?

Read more comments on GitHub >

github_iconTop Results From Across the Web

require.js text plugin adds ".js" to the file name - Stack Overflow
I have two web servers: localhost:3000 - act as CDN and has all the static files: js, images, css and templates; localhost:3001 -...
Read more >
RequireJS API
For example, this arrangement will fail randomly when the require.config path ... //my/shirt.js now has some dependencies, a cart and inventory //module in ......
Read more >
RequireJS - Quick Guide - Tutorialspoint
RequireJS is a JavaScript library and file loader which manages the dependencies between JavaScript files and in modular programming.
Read more >
Getting Started with Video.js - Video.js: The Player Framework
js CDN. Our friends at Fastly are nice enough to provide hosting for all the necessary files for Video.js on their content delivery...
Read more >
Video.js - Make your player yours | Video.js
The world's most popular open source HTML5 player framework.
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