RangerMauve / webrun

Run Web-first ESM modules outside of the browser
https://webrun-presentation.hashbase.io/
MIT License
77 stars 8 forks source link

require works only if webrun is installed as local dependency #18

Closed Gozala closed 5 years ago

Gozala commented 5 years ago

Forking this from #16 so issue isn't derailed to this.

Oh wow, I think it's because I'm a dingus.

https://github.com/RangerMauve/webrun/blob/master/src/plugins/node.js#L67

Basically, it uses the require logic relative to where webrun is installed rather than the present working directory. Not 100% sure what to do about that unless there's a module that lets you require relative to an arbitrary path.

Gozala commented 5 years ago

@RangerMauve I think it actually might be reasonable to expect to request relative path from the given module for self.require in which case it should be fine no ?

The larger question is how do I create library that depends on the node module, because there's no way for my library to make those dependencies available.

RangerMauve commented 5 years ago

@Gozala I kinda wanted to avoid libraries that mix Node and web modules like that, honestly.

Ideally, things using Webrun will avoid using Node APIs in order to be compatible with the web, and if there's some Web APIs that are missing, they should be added to webrun core.

RangerMauve commented 5 years ago

Ideally you should pass all your node dependencies into webrunify and build a bundle that you can then import.

brechtcs commented 5 years ago

Note that not all node builtins will work with webrunify. Because under the hood it uses Browserify, some modules are replaced with versions that only implement browser-relevant features (e.g. http and os) or with complete no-ops (e.g. child_process and net).

Not sure yet what's the best way to handle those, and whether it should be dealt with here or in webrunify. So yeah, all ideas welcome! :)