Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot assign to read only property 'ok' of object '[object Object]' while running in browser #130

Closed
kim366 opened this issue Oct 24, 2020 · 3 comments

Comments

@kim366
Copy link

kim366 commented Oct 24, 2020

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
@twada
Copy link
Member

twada commented Oct 25, 2020

@kim366 Thank you for reporting!
I'll take a look.
Would you make a small repository or gist for reproduction of this case?

@kim366
Copy link
Author

kim366 commented Oct 25, 2020

Yes, of course. Here it is: https://github.com/kim366/repro-power-assert

  1. git clone https://github.com/kim366/repro-power-assert.git
  2. npm install && npm start
  3. Open http://localhost:8080/test/TestRunner.html
  4. Open Devtools

Hope this helps.

@twada
Copy link
Member

twada commented Oct 28, 2020

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.

@kim366 kim366 closed this as completed Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants