Closed
Description
What happened
As of 4.0.0-rc.11
the hash
function no longer works with moment
values.
It gives an error of:
/test/immutablejs-test/node_modules/immutable/dist/immutable.js:882
weakMap.set(obj, hashed);
^
TypeError: Invalid value used as weak map key
at WeakMap.set (<anonymous>)
at hashJSObj (/test/immutablejs-test/node_modules/immutable/dist/immutable.js:882:15)
at hash (/test/immutablejs-test/node_modules/immutable/dist/immutable.js:794:16)
at Object.<anonymous> (/test/immutablejs-test/index.js:6:14)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
How to reproduce
Run the following program with immutable:4.0.0-rc.11
, moment:2.22.2
, node:v9.11.2
:
const { hash } = require('immutable');
const moment = require('moment');
const now = moment();
const res1 = hash(now)
console.log('hash of moment', res1);
Above works on 4.0.0-rc.10
, but fails on rc.11
and rc.12
.
FWIW, I can work around this on my side and it isn't a good practice to hash a mutable variable anyway. But I wanted to report it in case it's a symptom of a bigger issue.