ritz078 / embed-js

🌻 A lightweight plugin to embed emojis, media, maps, tweets, code and more. ✨
https://codesandbox.io/s/Wp5OlNMn
MIT License
1.27k stars 89 forks source link

Cant require(embed-js) in Node #180

Closed pursual closed 7 years ago

pursual commented 8 years ago

var EmbedJS = require('embed-js');

Gives error

TypeError: Cannot read property 'fetch' of undefined
    at /xxx/node_modules/embed-js/src/embed.js:916:15
    at /xxx/node_modules/embed-js/src/embed.js:1299:7
ritz078 commented 8 years ago

any chance I can see the code ?

pursual commented 8 years ago

That is the code so far. It fails as soon as I require. I haven't gotten past that point. Might be a node thing? v4.4.7

ritz078 commented 8 years ago

I tried it and its working fine for me. are you sure you are using v4.1.4 ? maybe if I can see your code, I will be able to help or if its not possible lets discuss here. can you send the screenshot ?

pursual commented 8 years ago

I installed by npm and it seems to be 4.1.4. I was able to get it to work by setting self = {}; and commenting out the references to "window" in the default options. Its obviously not really meant to run in node. Like I said, there is no code for you to see. It fails on require because self is undefined.

pursual commented 8 years ago

Node doesnt have a "self" or "window" global...so your code wont work.

ritz078 commented 8 years ago

of course this is not an isomorphic code. it will only run on client side :)

pursual commented 8 years ago

Yeah, just confusing that you use npm, which is mainly for node. I wanted to use it in Node with the .text() function.

ritz078 commented 8 years ago

I will try to make this isomorphic.

MaxLeiter commented 7 years ago

being able to do server-side fetching would be awesome (esp. for caching)

ritz078 commented 7 years ago

yes. for that i will also have to separate code that handles interactions like click, load etc. But that should be surely doable.

niko-h commented 7 years ago

I installed embedjs via meteor npm install --save embed-js and the module seems to be installed properly @4.1.13. Requiring it via import EmbedJS from 'embed-js'; does not work though. It gives me an

Uncaught Error: Cannot find module 'embed-js'

Any suggestions?

ritz078 commented 7 years ago

If the error is that the module hasn't been found, it should be something specific to meteor. Someone with meteor experience may help.

niko-h commented 7 years ago

I guess some kind of meteor-wrapper-package would have to be written. Unfortunately I don't see myself up to this task. Thumbs up anyway for embed.js! Didn't find an alternative with as many supported embeds yet.

ritz078 commented 7 years ago

@niko-h Can you open a separate issue so that I can try to fix this.

ritz078 commented 7 years ago

isomorphic support available in v5 beta.