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.

Webpack problem - Cannot resolve module 'videojs'

See original GitHub issue

Description

I am using webpack with babel es2015 loader and getting a compile error due to the AMD import in videojs.record.js.

Seems to be related to #123.

Steps to reproduce

(after installing recordrtc, videojs and videojs-record via npm)

index.js

require('recordrtc');
const  videojs = require('video.js');
require('videojs-record');

const player = videojs('auth-video-player', {
  // video.js options
  controls: true,
  loop: false,
  width: $('#auth-video-container').width() || 320,
  height: $('#auth-video-container').height() || 240,
  plugins: {
    // videojs-record plugin options
    record: {
      image: false,
      audio: true,
      video: true,
      maxLength: 5,
      debug: true
    }
  }
});

// error handling
player.on('deviceError', function() {
  console.log('device error:', player.deviceErrorCode);
});

player.on('error', function(error) {
  console.log('error:', error);
});

// user clicked the record button and started recording
player.on('startRecord', function() {
  console.log('started recording!');
});

// user completed recording and stream is available
player.on('finishRecord', function() {
  // the blob object contains the recorded data that
  // can be downloaded by the user, stored on server etc.
  console.log('finished recording: ', player.recordedData);
});

I have tried with and without the ProvidePlugin with no change in results:

webpack.config.js

plugins: [
  new webpack.ProvidePlugin({
    $: 'jquery',
    jQuery: 'jquery',
    'window.jQuery': 'jquery',
    videojs: 'video.js',
    'window.videojs': 'video.js'
  }),
]

Results

Expected

It should be able to import the video.js dependency which has already been required.

Actual

webpack cannot compile due to module error.

Error output

webpack error

Module not found: Error: Cannot resolve module 'videojs' in [...]/app/node_modules/videojs-record/src/js

Additional Information

I’m able to compile successfully by changing line 6 of video.record.js to reference video.js instead of videojs, which is the name of the package in node_modules. However, I get a console error in the browser when I try to enable the video:

device error: ReferenceError: MRecordRTC is not defined
    at subClass.setup (main.js:79422)
    at constructor.onDeviceReady (main.js:80035)

I’m requiring RecordRTC before video.js and videojs-record so not sure why this is happening here.

versions

videojs

5.16.0 (latest on npm)

browsers

Chrome 56

OSes

Mac OSX 10.12.3

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jonathanfalloncommented, Sep 19, 2018

Works fine for me with resolve: {alias: {videojs: 'video.js'}} Thanks for the tutorial

Read more comments on GitHub >

github_iconTop Results From Across the Web

Video JS in Angular 9 - live video - 'Can't resolve videojs ...
I think the problem is your webpack.alias doesn't get affected. On the other hand, your webpack.config.js is not applied yet.
Read more >
Resolve | webpack
Configure how modules are resolved. For example, when calling import 'lodash' in ES2015, the resolve options can change where webpack goes to look...
Read more >
videojs-errors - npm
A plugin that displays user-friendly messages when Video.js encounters an error. Maintenance Status: Stable. Getting Started. Localization ...
Read more >
How to fix error TS7016: Could not find a declaration file for ...
Try `npm install @types/XYZ` if it exists or add a new declaration (.d.ts) file containing `declare module 'XYZ';. If XYZ is a direct...
Read more >
App.js missing dependencies when adding new package
Hi guys I am trying to add videojs-records to my Laravel 6 project . ... Module not found: Error: Can't resolve 'videojs' in ......
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