Error with mongodb when using Atlassian Connect Express 8.1.1+

I’ve been looking at updating Atlassian Connect Express (ACE) to the very latest version.

My app uses ACE with postgres (in dev, …, and production).

:white_check_mark: Using ACE v8.0.2 it works

:x: Using ACE v8.1.0 it does not work

:x: Using ACE v8.2.0 it does not work

It does not start. Here’s the console messages (which are the same for both v8.1.0 & v8.2.0):

npm run watch-server                                        

> my-app@1.0.0-AC watch-server
> NODE_ENV=development nodemon -r dotenv/config -r esm app.js

[nodemon] 2.0.20
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node -r dotenv/config -r esm app.js`

...

/path/to/my-app/node_modules/mongodb/lib/collection.js:74
            pkFactory: db.options?.pkFactory ?? utils_1.DEFAULT_PK_FACTORY,
                                  ^

SyntaxError: Invalid or unexpected token
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)

Node.js v18.12.1
[nodemon] app crashed - waiting for file changes before starting...

Whats the difference?

From the release notes:

8.2.0

  • Added support for FedRAMP sandbox tenants for OAuth2 and installation callbacks

8.1.1

  • Update dependency sqlite3 to v5.1.6
  • Update dependency @aws-sdk/client-dynamodb to v3.398.0

8.1.0

  • Update dependency mongodb to v5. Note: only the Node.js driver was updated and the new version is still compatible with MongoDB 3.6 and later.

It looks like the update to mongodb v5 in ACE 8.1.0 broke things.

:point_right: I’m not even using anything to do with mongodb, so why is my app now broken with ACE v8.2.0?

Note: I’m running the app using esm using the following watch-server in package.json:

"watch-server": "NODE_ENV=development nodemon -r dotenv/config -r esm app.js",

Aside, here’s my abridged config.json:

{
  development: {
    ...
    "store": {
      "adapter": "sequelize",
      "type": "postgres",
      "url": "postgres://username:@localhost:5432/gaij"
      // assumed that your development machine user is `username` and you're running Postgres w/o a password
    },
  },
  ...
}
1 Like

Looks like MongoDB Nodejs Driver 5 introduced optional chaining in the codebase that requires Node.js v14 or higher. What version of Node.js are you running? Would it be possible for you to update? And what version of esm are you running?

2 Likes

@jweiss Thanks for your reply.

I am currently running node 18.12.1 & esm 3.2.25.

My abridged package.json:

{
  ...
  "engines": {
    "node": "18.12.1",
    "npm": "8.19.2"
  },
  ...
  "dependencies": {
    ...
    "esm": "^3.2.25",
    ...
  },
  ...
}

Hi @david ,
the problem is probably with ESM. ESM does not support optional chaining.
You can remove ESM if your code dos not mix ES6 and require, or if your files are called with suffix .mjs and .cjs or you use the module specifier in your package.json.

1 Like

Hello @david/@jweiss

I am trying to upgrade ace to latest version of 8.2.0 from 7.x.x. I was also using esm 3.2.25. But after reading this thread, I removed esm, made “type”=“module” in package.json, removed all require and converted them to imports. Now I am getting below error whenever I am trying to pass my express app to ace function

xyz/node_modules/mongodb/lib/connection_string.js:273
[SERVER] throw new error_1.MongoParseError(${optionWord} ${Array.from(unsupportedOptions).join(', ')} ${isOrAre} not supported);
[SERVER] ^
[SERVER]
[SERVER] MongoParseError: option logger is not supported
[SERVER] at parseOptions ()
[SERVER] at new MongoClient (
[SERVER] at ModuleJob.run (node:internal/modules/esm/module_job:194:25) {
[SERVER] [Symbol(errorLabels)]: Set(0) {}
[SERVER] }
[SERVER]
[SERVER] Node.js v18.17.1

Do you guys have any suggestions?

1 Like

Hi @TejasKatariya,

I think this error message is due to the upgrade from the MongoDB Node.js Driver v4 to v5. According to the documentation, the logger option has been removed.

Apparently, these option didn’t have any effect, so from my understanding you can omit it from the options that you pass to the MongoClient constructor or from MongoClient.connect().

I hope that helps. If you’re still getting this error, can you share the code where you pass the logger?

Hi @jweiss, Actually I am not using MongoClient.connect() anywhere in my application, error stack shows from ace package

Uncaught MongoParseError MongoParseError: option logger is not supported
at parseOptions (/node_modules/mongodb/lib/connection_string.js:273:15)
at MongoClient (/node_modules/mongodb/lib/mongo_client.js:48:63)
at MongoDbAdapter (/node_modules/atlassian-connect-express/lib/store/mongodb.js:64:20)
at module.exports (/node_modules/atlassian-connect-express/lib/store/mongodb.js:241:10)
at stores.create (/node_modules/atlassian-connect-express/lib/store/index.js:20:10)
at stores (/node_modules/atlassian-connect-express/lib/store/index.js:12:17)
at Addon (/node_modules/atlassian-connect-express/lib/index.js:45:38)
at module.exports (/node_modules/atlassian-connect-express/lib/index.js:284:10)
at (/app.js:38:15)
at run (internal/modules/esm/module_job:194:25)

Hi @TejasKatariya,
I have to apologise: the error comes from within ACE where we still pass that option to the MongoClient constructor. I’ve created a PR to patch ACE as soon as possible. Bitbucket

Can you update to atlassian-connect-express v8.2.1 and check if the MongoParseError is now gone @TejasKatariya?

1 Like

Thank you @jweiss !!
Sure let me check

Hi @jweiss,

It is still not working for me. Tried with 8.4.0, Same error.
I was going through code and I see below code in
node_modules/atlassian-connect-express/lib/store/mongodb.js:229:10)
where logger is still used

module.exports = function (logger, opts) {
if (0 === arguments.length) {
return MongoDbAdapter;
}
return new MongoDbAdapter(logger, opts);
};

Hi @TejasKatariya, I’m sorry to hear that. Can you make sure that your store configuration does not contain "logging": true?

I just realised that if a config like this is used, it’ll still error out:

"store": {
  "adapter": "mongodb",
  "url": "mongodb://localhost:27017/my_addon_database",
  "collection": "AddonSettings",
  "logging": true
}

I’ll update ACE to make sure that this use case is covered and the error won’t happen.

The logger that’s passed to the adapter is fine, that still can be used in connectionPromise().

Thanks again for bringing this issue to our attention. Due to the changes made by MongoDB we need to re-work the way ACE currently supports using a custom logger.

1 Like

Hello @jweiss Thank you so much for your help, By removing the logger from config, it worked.
I am facing different issues now with esm. I will resolve them, but thank you again for your quick responses!!

By removing esm, it is expecting to write file extension like .js after each import statement as i have used type: “module” in package.json