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

preact/debug error only in v8.2.6 #924

Closed
whitetrefoil opened this issue Oct 26, 2017 · 11 comments
Closed

preact/debug error only in v8.2.6 #924

whitetrefoil opened this issue Oct 26, 2017 · 11 comments

Comments

@whitetrefoil
Copy link

After upgraded my project from [email protected] to v8.2.6, I had this error when loading the page:

debug.js:49 Uncaught TypeError: Cannot set property render of #<Object> which has only a getter

// debug.js:L49
preact.render = function (vnode, parent, merge) {

If I stop requiring preact/debug it would be OK. I require it like this:

window['Promise'] = require('promise-polyfill')

if (process.env.ENV === 'production') {
  // Production
} else {
  // Development
  Error['stackTraceLimit'] = Infinity
  require('preact/debug')
}

When using v8.2.5 it was all good.

I'm using only preact with webpack@2 without preact-compat or any react related stuff.

@brunomolteni
Copy link

I'm also having the same issue

@Kanaye
Copy link

Kanaye commented Oct 27, 2017

The render() override was added in preact 8.2.6 or to be specific in #885.
The problem is the ES module exports are "read only" per rfc.
Webpack defines ES module exports as getter only properties and that is why this override fails.

I'm not sure what could be a viable long term solution for this.

For now you can just add

  'preact$': 'preact/dist/preact.js'

to the alias section of your webpack config.
This will ensure that webpack uses the commonjs version of preact and therefore the exports won't be readonly.

@NekR
Copy link
Collaborator

NekR commented Oct 28, 2017

I'm not sure what could be a viable long term solution for this.

The solution would be to not use require('preact') in preact/debug.

@NekR
Copy link
Collaborator

NekR commented Oct 28, 2017

The solution in original preact/debug was to use require('../') and override preact.h, when we changed to using preact.options.vnode it was possible to just use require('preact').

I'm not sure, but there possible could be an issue with webpack if we are going to use require('../') or require('preact/dist/preact.js') -- it may include the code twice.

@NekR
Copy link
Collaborator

NekR commented Oct 28, 2017

@whitetrefoil you don't have to guard preact/debug with process.env.NODE_ENV guard, it does so for you automatically. That's why it's better to use than preact/devtools.

@developit
Copy link
Member

Might be worth just wrapping the render override in a try/catch. We can inject it in Webpack 2.

developit added a commit that referenced this issue Nov 17, 2017
@NekR
Copy link
Collaborator

NekR commented Nov 17, 2017

That's webpack 2+, not only wepback 2.

@NekR
Copy link
Collaborator

NekR commented Nov 17, 2017

The thing what you did is not a fix.

@developit
Copy link
Member

We can't really work around this though - the object returned from require('preact') is immutable in Webpack 2+.

@NekR
Copy link
Collaborator

NekR commented Nov 21, 2017

I think there should be a way. I'll take a look into that later this week.

@paranoidjk
Copy link
Contributor

came across same problem, i think we should at least add some notice in Readme.

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

6 participants