`Cannot assign to read only property 'ok' of object '[object Object]'` while running in browser
kim366 opened this issue · 3 comments
Hello. I am trying to run power-assert in the browser using webpack and babel. The code transformation works great, but there is an error pointing to the return statement of the following line:
https://github.com/power-assert-js/power-assert/blob/master/build/power-assert.js#L13557
Here comes the stack trace:
Uncaught TypeError: Cannot assign to read only property 'ok' of object '[object Object]'
at assign (<anonymous>)
at eval (eval at empowerAssertObject (power-assert.js:4495), <anonymous>:1:1)
at empowerAssertObject (power-assert.js:4495)
at empowerCore (power-assert.js:4482)
at empower (power-assert.js:4663)
at applyEmpower (power-assert.js:17203)
at customize (power-assert.js:17209)
at power-assert.js:17226
at createCommonjsModule (_commonjsHelpers-4f955397.js:14)
at power-assert.js:17172
@kim366 Thank you for reporting!
I'll take a look.
Would you make a small repository or gist for reproduction of this case?
Yes, of course. Here it is: https://github.com/kim366/repro-power-assert
- git clone
https://github.com/kim366/repro-power-assert.git
npm install && npm start
- Open http://localhost:8080/test/TestRunner.html
- Open Devtools
Hope this helps.
Thank you for your repro case.
I've found that Rollup, where used internally by Snowpack, freezes assert
module by default.
var assert$1 = /*#__PURE__*/Object.freeze({
__proto__: null,
'default': assert,
AssertionError: AssertionError,
fail: fail,
ok: ok,
assert: ok,
equal: equal,
notEqual: notEqual,
deepEqual: deepEqual,
deepStrictEqual: deepStrictEqual,
notDeepEqual: notDeepEqual,
notDeepStrictEqual: notDeepStrictEqual,
strictEqual: strictEqual,
notStrictEqual: notStrictEqual,
throws: throws,
doesNotThrow: doesNotThrow,
ifError: ifError
});
Also found that Rollup has a freeze
option for opting-out of Object.freeze
usage.
refs: rollup/rollup#1696
So if you can pass freeze
option to Rollup via Snowpack, power-assert might work.