Not able to Import or Require a module(JS NPM Package) in a JS file inside the JS folder of any app

Currently, I am trying to use a sample Nextcloud app, install an npm package in the app, and access the package by using the import/require keyword in the js files present in the apps/sampleapp/js directory.

I am able to successfully install the package by npm i or npm install but whenever I’m trying to access the installed package in the apps’ JS files, it throws up the following error:

Uncaught SyntaxError: Cannot use import statement outside a module

Was anyone ever stuck at the same place or has a solution for it? It would be really helpful!

Thanks in advance!