`Cannot read property 'format' of undefined` on record update

Expected behavior

Editing fields should work as usual.

Actual behavior

Editing any field results in the following error:

Cannot read property ‘format’ of undefined

Failure Logs

We’ve tracked down the issue to the timezone variable not being found in params in the internal ResourceUpdater (node_modules/forest-express-sequelize/dist/services/resource-updater.js).

When logging this._params line 33 of the file, this is what we see: { recordId: '[truncated by OP]' }

We do see the timezone GET parameter in the logs URL:

PUT /forest/MyModel/[truncated by OP]?timezone=Europe%2FParis 500 100 - 46.201 ms

This causes the offsetClient computation in the BaseOperatorDateParser to crash, possibly due to a Babel issue.

Exact location of crash in node_modules/forest-express/dist/services/base-operator-date-parser.js line 35:

var offsetClient = Number.parseInt((0, _momentTimezone["default"])().tz(options.timezone).format('Z'), 10);

The crash happens after .tz returns undefined. This may be unexpected behaviour caused by Babel as we’ve found that .tz, when called via a simple require instead of the interop layer, returns a proper Moment object:

var momentTimezone = require('moment-timezone')
momentTimezone.tz(undefined) // returns a Moment object

var interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var momentTimezoneInterop = interopRequireDefault(require("moment-timezone"))
momentTimezoneInterop['default']().tz(undefined) // returns undefined

Context

Please provide any relevant information about your setup.

  • Package Version: forest-express-sequelize 8.0.9, forest-express 9.1.1
  • Express Version: 4.17.1
  • Sequelize Version: 6.6.5
  • Database Dialect: MSSQL
  • Database Version: -
  • Project Name: -

This does not happen in our development environment but only in the staging and production environments. The development environment runs on Windows machines, the staging and prod run on Docker (node:16).

We have recently upgraded to V8.

Hi @kll :wave:

That’s weird indeed, since this issue was fixed in 8.0.5 of forest-express-sequelize (forest-express 9.0.3) & I’m currently not able to reproduce.

Could you run a npm ls forest-express-sequelize on an environment where the update fails?
Do you use any load balancer that could potentially run using an older version (before 8.0.5)?

1 Like

Thanks for the info! Turns out we were using npm install instead of npm ci and I suspect that a cache somewhere was effing things up.

Rolled to npm ci, checked the versions used in prod, and it all seems good now.

I no longer have access to an environment where I can reproduce this as we switched to npm ci shortly before your post but well, this seems like the root cause.

Thanks for your lightning-fast reply. Have a nice weekend!

1 Like