I am using the kahoot-api NPM module (GitHub, NPM) and it requires using JavaScript import. (edit, this is a Node.js package. I didn't know the difference between JS and Node.js at the time of writing this, this is why this question was created).
The documentation says to use the following JavaScript import script to import Session and Adapters:
import { Session, Adapters } from 'kahoot-api';
This throws an error saying that I need to use a relative reference.
Failed to resolve module specifier "kahoot-api". Relative references must start with either "/", "./", or "../".
My files and folders are structured as so:
- index.php
- node_modules
- @omegaboot
- kahoot-api
All of the NPM files for kahoot-api are inside of the kahoot-api folder.
I have modified my JavaScript code to use a relative reference, as shown below.
import { Session, Adapters } from './node_modules/@omegaboot/kahoot-api/';
No errors are thrown, however the two imported statements Session and Adapters are not available, and still undefined.
import { Session, Adapters } from './node_modules/@omegaboot/kahoot-api/';
const session = new Session('000000');
session.openSocket() //Connect
.then(socket => {
const player = new Adapters.Player(socket); //Create player class
player.join('test') //Join with name
.then(() => {
console.log('Success!');
});
});
There are multiple JavaScript files inside of the kahoot-api folder, and I have tried including each JavaScript file with the JavaScript import, but to no avail.
Also, I am using the code in index.php with a <script> tag with the attribute type="module" as it is needed, or else the following error is thrown:
Cannot use import statement outside a module
importstatement does not support directly in nodejs.require('module-name')instead ofimportstatement.import { Session, Adapters } from '@omegaboot/kahoot-api';Failed to resolve module specifier "@omegaboot/kahoot-api". Relative references must start with either "/", "./", or "../"..