I'm trying to use the library videojs-abloop
My nodejs version is v12.18.3
First I installed two libraries as asked from videojs-abloop :
npm install video.js videojs-abloop
Then ran the command
$ node --experimental-modules index.js
Error output
$ node --experimental-modules index.js
(node:31057) ExperimentalWarning: The ESM module loader is experimental.
/my_path/testimport/node_modules/videojs-abloop/videojs-abloop.js:8
export default function (window, videojs) {
^^^^^^
SyntaxError: Unexpected token 'export'
I two files : index.js and package.json :
index.js
import videojs from 'video.js'
import abLoopPlugin from 'videojs-abloop'
abLoopPlugin(window,videojs);
package.json
{ "type": "module" }
I checked about the ESM imports but Node.js 12 : ESM Imports, but I think it is not related to this problem
It is impossible to tell just from looking at a file whether it is an ECMAScript Script or an ECMAScript Module. Therefore, you need to tell the engine which of the two it is.
On the web, this is solved via different MIME Types, but MIME Types don't exist on filesystems, so Node.js uses the file extension (.mjs) or the type field in package.json ("type": "module") to distinguish between the two.
As the documentation says [Note: I am quoting from the latest docs, but the only difference is whether ESM are enabled by default or not]:
Enabling
Experimental support for ECMAScript modules is enabled by default. Node.js will treat the following as ES modules when passed to node as the initial input, or when referenced by
importstatements within ES module code:
- Files ending in
.mjs.- Files ending in
.jswhen the nearest parentpackage.jsonfile contains a top-level field"type"with a value of"module".- Strings passed in as an argument to
--eval, or piped to node viaSTDIN, with the flag--input-type=module.
There are several pages more about how exactly Node.js determines whether a file is an ECMAScript Script or an ECMAScript Module.
You seem to have an outdated or somehow broken version of videojs-abloop. According to the GitHub Issues, and particularly this commit, videojs-abloop is written as an ECMAScript Module but is transpiled to an ECMAScript Script. In your case, for some reason, you have an ECMAScript Module instead of an ECMAScript Script of videojs-abloop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With