External package gives error

Hi,

Im trying to add an external package, node-mavlink, to be able to use it in a function node in a node red flow.

Im running node red in docker so Ive installed the package in /data and updated the settings.js file:

functionGlobalContext: {
    mavlink:require('node-mavlink'),
    // os:require('os'),
},

Reading the logs after restarting node red I get:

nodered | Error loading settings file: /data/settings.js
nodered | /data/node_modules/node-mavlink/dist/lib/mavesp.js:44
nodered | this.socket?.bind(receivePort, () => {
nodered | ^
nodered |
nodered | SyntaxError: Unexpected token '.'
nodered | at wrapSafe (internal/modules/cjs/loader.js:915:16)
nodered | at Module._compile (internal/modules/cjs/loader.js:963:27)
nodered | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
nodered | at Module.load (internal/modules/cjs/loader.js:863:32)
nodered | at Function.Module._load (internal/modules/cjs/loader.js:708:14)
nodered | at Module.require (internal/modules/cjs/loader.js:887:19)
nodered | at require (internal/modules/cjs/helpers.js:74:18)
nodered | at Object. (/data/node_modules/node-mavlink/dist/index.js:21:14)
nodered | at Module._compile (internal/modules/cjs/loader.js:999:30)
nodered | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

Is it a faulty package or have I missed somthing(most probably)?

Regards,
Ludvig

the library is using Optional chaining (?.) ..
which based on the MDN website this syntax is supported
in Nodejs version 14 and up.

Can you check that the docker container is using the appropriate Nodejs >= 14 version ?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.