0

I want to try the following npm package, camera-capture, to capture videos from my webcam. I am very new to both npm and typescript, so I'm not sure how to test it properly. What I did so far is the following:

  1. Copied this example, then saved it in an index.js file
  2. Tried executing it from the terminal using node index.js

I received the following error:

SyntaxError: Cannot use import statement outside a module

I know that what I'm doing might be so wrong, however, as a beginner, the explanation on the package's homepage is not enough for me, I need to know about further steps to make it work properly.

My question is: How to set the proper environment to run a test for this library?

Ken White
  • 123,280
  • 14
  • 225
  • 444
philippos
  • 1,142
  • 5
  • 20
  • 41

2 Answers2

0

So I resolved the import problem specifically by the following:

  1. Copied this example, then saved it in an index.ts file
  2. Compiled it using tsc index.ts,
  3. Executed the resulting js file from the terminal using node index.js

This resolved the import problem. However, other problems were thrown (not related to this question, as I think),

philippos
  • 1,142
  • 5
  • 20
  • 41
-1

You could try

const VideoCapture=require('camera-capture')

instead of

import {VideoCapture} from 'camera-capture'

  • that makes it "somehow" work, but that's not a complete answer. I have been searching around and I found this question that explains the difference between `import` and `require` https://stackoverflow.com/questions/46677752/the-difference-between-requirex-and-import-x – philippos May 19 '20 at 06:48