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

Doesn't seem to work with Deno #93

Open
vikanezrimaya opened this issue Jun 21, 2020 · 4 comments
Open

Doesn't seem to work with Deno #93

vikanezrimaya opened this issue Jun 21, 2020 · 4 comments

Comments

@vikanezrimaya
Copy link

Deno is a new JS server environment that was created from ground up in attempt to fix Node.js's drawbacks. It looks like this library somehow confused it with a browser (uses process to distinguish Node and browser probably?) Deno doesn't have process, it has its own Deno object in the global namespace, and it uses ES6 modules and not NPM packages.

Hyperscript is small, compact and relatively self-contained, just like Deno. I think they would play together rather nicely.

@rschristian
Copy link

Hyperscript does not check for process, it does a standard window check to determine browser vs Node:

var w = typeof window === 'undefined' ? require('html-element') : window

@jsejcksn
Copy link

jsejcksn commented Jul 22, 2021

it does a standard window check to determine browser vs Node:

This is an older assumption that window means "browser". Deno also has globalThis.window.

The next line is where the assumption goes wrong:

hyperscript/index.js

Lines 4 to 5 in 4c0d558

var w = typeof window === 'undefined' ? require('html-element') : window
var document = w.document

(If environment is unknown, each feature should be tested before being used.)

All that being said, Hyperscript predates Deno by quite a bit, back in a time where a JavaScript "client" meant "browser" and "server" meant "Node.js".

@kisik21 Deno doesn't have any DOM support yet, so it would need to provide that feature before something like hyperscript could support it as an environment.

@vikanezrimaya
Copy link
Author

In Node there's html-element used to simulate a minimal DOM enough to make HTML. If the check in L4-5 is changed to detect absence of window.document instead of just window (which Deno has, unlike Node), then one could easily make it work with Deno via a proxy that rewrites requires to ES6 imports (that's how I originally tried to launch this package, and it would've worked if the check didn't failed.

I may try to make a PR in the near future. Something like extending the L5 with var document = typeof w.document === 'undefined' ? require('html-element') : w.document - should probably make it work with Deno after rewriting imports.

@jsejcksn
Copy link

should probably make it work with Deno after rewriting imports

@kisik21 It's a little more complicated than that. Neither html-element nor its chain of npm dependencies provide ES modules (they only support CommonJS). Because Deno only supports esm with explicit specifiers, you'd have to refactor every module in every dependency (and dependency of dependency... and so on: all the way to the end of the module graph) to that format.

If you don't want to go that route, you could look at other community modules for DOM in Deno (e.g. https://deno.land/x/deno_dom).

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

3 participants