Import external libraries in JS ServerCode

I’m trying to create an API service using JS. I downloaded the project template and started editing it in VS Code.
Everything worked well until I added an external module to the code

'use strict';

import * as Random from "random";

class SampleService2 {
  sampleService2Method(name) {

    return {"message": Random.float(0, 10)};

SampleService2.version = '1.0.0';


If I remove the import statement all works well, otherwise, while deploying via npm run deploy I get this error:
19:07:36.736 Errors (1):
19:07:36.745 Cannot use import statement outside a module (services\bcd\SampleService2.js)
19:07:36.746 Error: Please resolve Model Errors before deploying to production.

Can anyone help me? Thank you in advice

Hi Marco,

Please see the following section from the documentation:

How did you import the external module? Did you add it as a dependency in package.json?


The “import” sintax does not work but if I use the require command it works.
Thank you