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

Does not work with server-side rendering #91

Closed
jsardev opened this issue May 12, 2019 · 10 comments
Closed

Does not work with server-side rendering #91

jsardev opened this issue May 12, 2019 · 10 comments

Comments

@jsardev
Copy link

jsardev commented May 12, 2019

The below error is being thrown:

import parse from 'posthtml-parser';
       ^^^^^
SyntaxError: Unexpected identifier

I was digging around a little bit and... why the server.js file is not being published in CommonJS format? I guess that this might be the problem here.

@jsardev
Copy link
Author

jsardev commented May 12, 2019

Transforming all the files to cjs format does resolve the issue.

What do you think about providing a cjs version of this library? Publishing an ES6+ version to npm is IMO not a good idea, as in most projects you exclude your node_modules from passing it via babel.

@pveyes
Copy link
Owner

pveyes commented May 12, 2019

Hi @sarneeh thanks for the report. Could you try using v0.7.x and check if it works? There's should be no code change with v0.8 (only bundle & publish change)

@jsardev
Copy link
Author

jsardev commented May 12, 2019

@pveyes 0.7.0 works fine. Also the bundle looks good. It crashes on 0.8.x.

@Arcath
Copy link
Contributor

Arcath commented May 13, 2019

What node version are you using?

I'm using HTMR 0.8.1 with Gatsby no problem on my machine. (Node 10.15.3)

@jsardev
Copy link
Author

jsardev commented May 13, 2019

@Arcath 10.15.1. Also, I'm using HTMR with NextJS which compiles the client and also server code. Now I realised that I'm actually not sure if this is a client or a server failure 😄

@Arcath
Copy link
Contributor

Arcath commented May 13, 2019

posthtml-parser is only used in the server.js not browser.js.

That being said NextJS will be bundling the server side code for use in the browser as your importing convert from htmr not htmr/lib/browser

I'm looking rewriting the browser bundle to use the server-side parsing anyway to clear up a bug I am having on my site.

@jsardev
Copy link
Author

jsardev commented May 15, 2019

@Arcath You're right! Thanks for solving this little mystery to me 😄

@jsardev jsardev closed this as completed May 15, 2019
@IOIO72
Copy link

IOIO72 commented May 17, 2019

Hi! I'm getting the same error - independently of using html or htmr/lib/browser when I build my productive code with React Static. I've downgraded to 0.7 and it works fine.
So there might be a bug. Or am I'm getting something wrong?

@jsardev
Copy link
Author

jsardev commented May 17, 2019

@IOIO72 I admit that I actually did not test the suggestion from @Arcath as it did sound like a logic cause of this issue. I'll check it out in my project today.

@jsardev
Copy link
Author

jsardev commented May 17, 2019

@Arcath @IOIO72 Is right. I'm getting the same issue while using htmr/lib/browser, but from different thing. The problem is that the code is not transpiled to cjs.

import React from 'react';
       ^^^^^
SyntaxError: Unexpected identifier

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

4 participants