You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I tried to upgrade moment from 2.29.1 to 2.29.4 to fix ReDos vunl (I think this is the same reason why 2.29.4 is release)
To Reproduce
Steps to reproduce the behavior:
In package.json, "dependencies": { ..., moment: "^2.27.0", ...}
In Terminal, type "yarn upgrade moment@2.29.4" to bump version
Can see 2.29.4 is download in node_modules and yarn.lock is updated automatically
Tried to build and start the app, failed.
Tried to console.log error, see TypeError: moment__WEBPACK_IMPORTED_MODULE_15___default(...)(...).tz is not a function
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
with 2.29.1, moment() object has 7 properties, see screenshot
with 2.29.4, moment() object has 6 properties, does not have the last '_z' property.
Desktop (please complete the following information):
OS: [e.g. iOS]
Browser [e.g. chrome, safari]
Version [e.g. 22]
Smartphone (please complete the following information if applicable):
Device: [e.g. iPhone6]
OS: [e.g. iOS8.1]
Browser [e.g. firefox, safari]
Version [e.g. 22]
Moment-specific environment
The time zone setting of the machine the code is running on
The time and date at which the code was run
Other libraries in use (TypeScript, Immutable.js, etc)
Please run the following code in your environment and include the output:
console.log((new Date()).toString()) //Fri Jan 13 2023 17:08:38 GMT+1100 (Australian Eastern Daylight Time)
console.log((new Date()).toLocaleString()) //13/01/2023, 17:08:38
console.log((new Date()).getTimezoneOffset()) //-660
console.log(navigator.userAgent); //Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
console.log(moment.version); // 2.29.4
Additional context
Code snippet
// helper.js
import moment from 'moment';
export const currentTZ = () => {
// console.log(Object.keys(moment())); // with 2.29.1, this works; the object has 7 properties, last one is "_z". with 2.29.4, this does not work; the object has 6 properties, does not have "_z" property.
return moment().tz("Australia/Sydney")
.format('Z') === '+11:00' ? 'AEDT' : 'AEST';
}
Any help is appreciated!
The text was updated successfully, but these errors were encountered:
Your code snippet doesn't seem to be importing moment-timezone anywhere, so it makes sense that .tz isn't available.
That said, if it worked before, I suspect there's a separate piece of code in your project that imports moment-timezone, which in turn mutates the underlying (and shared) moment object. With the upgrade to the newer moment version, that reference link might now be broken. See moment/moment-timezone#982 (comment) for a more detailed explanation of how there can be different versions of moment in the same project.
Thanks @gilmoreorless , it's very detailed explanations and great direction. Appreciated your help!
I am able to fix the issue by following steps:
In package.json -> "dependencies" -> remove removed "moment": "^2.27.0"; keep "moment-timezone": "^0.5.33"; then de-duplicate version, as suggested in How to fix it section in this thread. I ran below cmds in sequence.
$ yarn remove moment
$ npx yarn-deduplicate --packages moment
$ yarn install
In helper.js, updated the OLD imports to NEW imports
// OLD imports in helper.js
import moment from 'moment'; // <- removed this import
import momentTimezone from 'moment-timezone';
// NEW imports in helper.js
import moment from 'moment-timezone'; // <- update to only use one import from 'moment-timezone'
All unit tests are passing and build is successful now.
Describe the bug
I tried to upgrade moment from
2.29.1
to2.29.4
to fix ReDos vunl (I think this is the same reason why 2.29.4 is release)To Reproduce
Steps to reproduce the behavior:
TypeError: moment__WEBPACK_IMPORTED_MODULE_15___default(...)(...).tz is not a function
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
with
2.29.1
, moment() object has 7 properties, see screenshotwith
2.29.4
, moment() object has 6 properties, does not have the last '_z' property.Desktop (please complete the following information):
Smartphone (please complete the following information if applicable):
Moment-specific environment
Please run the following code in your environment and include the output:
Additional context
Code snippet
Any help is appreciated!
The text was updated successfully, but these errors were encountered: