Help with 'import' of NPM module for use with a custom Wappler Extension

Hey All,

I’ve got some custom JS that i’ve built for an app and it is all working fine except i can’t get it to work now that i’ve finished testing it and now trying to set it up as a Wappler extension.

I’ve used and built some extensions before so i can usually get them to work, the problem this time is i’m making use of the ‘regression.js’ module (https://www.npmjs.com/package/regression) and it seems to be built differently to other modules i’ve used in the past successfully (Nanoid and Lodash primarily)

The instructions of regression talk about loading it using import whereas all the other modules i’ve used use the require command.

I can’t use import in the wappler extension and i’ve tried using require but it can’t locate the regression module and throws an error like:

"ReferenceError: regression is not defined\n    at Object.getAutoRegression (/opt/node_app/extensions/server_connect/modules/forecast_engine.js:400:31)\n    at /opt/node_app/extensions/server_connect/modules/forecast_engine.js:372:65\n    at Array.forEach (<anonymous>)\n    at Object.getRegressionData (/opt/node_app/extensions/server_connect/modules/forecast_engine.js:360:18)\n    at forecastCalls (/opt/node_app/extensions/server_connect/modules/forecast_engine.js:828:48)\n    at /opt/node_app/extensions/server_connect/modules/forecast_engine.js:1106:9\n    at Array.forEach (<anonymous>)\n    at forecast_engine (/opt/node_app/extensions/server_connect/modules/forecast_engine.js:566:20)\n    at App.exports.forecast_engine (/opt/node_app/extensions/server_connect/modules/forecast_engine.js:1117:12)\n    at App._exec (/opt/node_app/lib/core/app.js:485:57)"

I’ve tried to write the require statement like:
require('regression') or const regression = require('regression')

but still can’t get it to work. I think the regression module isn’t packaged up to use require() ?? although my understanding of this part of JS and Node is limited.

For instance, in the regression folder in node_modules, it doesn’t’ have an index.js file like other modules i’ve worked with?

I wonder if its just a matter of specifying the path differently in the require statement?

Any thoughts would be much appreciated…apologises for the rambling :slight_smile:

Community Page
Last updated: