RangerMauve / hyper-sdk

Make your own hyper apps!
https://www.youtube.com/watch?v=HyHk4aImd_I&list=PL7sG5SCUNyeYx8wnfMOUpsh7rM_g0w_cu&index=20
MIT License
292 stars 45 forks source link

Cannot browserify dat-sdk #60

Closed genderev closed 3 years ago

genderev commented 3 years ago

index.js is simply const SDK = require('dat-sdk')

In my terminal:

browserify index.js > bundle.js
Error: Cannot find module 'babelify' from '/Users/my_user/Documents/GitHub/project/node_modules/dat-sdk'

So I tried npm install babelify then, again, browserify index.js > bundle.js My terminal:

Error: Cannot find module '@babel/core'
RangerMauve commented 3 years ago

Could you try installing the following and see if that helps?

"@babel/core": "^7.9.0",
    "babel-plugin-module-resolver": "^4.0.0",
    "babelify": "^10.0.0"
DougAnderson444 commented 3 years ago

I think you needed to add --save-dev to the cli

npm install babelify --save-dev

as babelify needs to be a devDependency

Also you need to add the babelify -transform to the command line

browserify -t [ babelify --global ] index.js > bundle.js

RangerMauve commented 3 years ago

@DougAnderson444 Thanks for chiming in, do you think you'd be up to submit a PR to the README which adds these details in the browserify section? Something along the lines of what you need to do to use the library in a browserify environment

RangerMauve commented 3 years ago

I think this is also related to https://github.com/RangerMauve/dat-fetch/issues/10

genderev commented 3 years ago

Could you try installing the following and see if that helps?

"@babel/core": "^7.9.0",
    "babel-plugin-module-resolver": "^4.0.0",
    "babelify": "^10.0.0"

Yep, I was able to browserify the file after installing all of these!

genderev commented 3 years ago

I don't know if I should make a new issue :/ My entire webpage looks like this:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head><meta charset="utf-8"><title></title>
  </head>
  <body></body>
  <script src="bundle.js"></script>
  <script>
    const SDK = window.datSDK
    // Look at the examples from here
  </script>
</html>

and I have this error in the console:

Uncaught Error: No native build was found for platform=browser arch=javascript runtime=node abi=undefined uv= libc=glibc node=undefined loaded from: /node_modules/sodium-native

DougAnderson444 commented 3 years ago

Hopefully these tips help.

The easiest way is to just start from the SDK bundle and work from there.

For the record, I couldn't get the webpack way working for the life of me. I gave up and switched to Browserify + Babelify.

DougAnderson444 commented 3 years ago

and I have this error in the console:

Uncaught Error: No native build was found for platform=browser arch=javascript runtime=node abi=undefined uv= libc=glibc node=undefined loaded from: /node_modules/sodium-native

You need to alias the sodium code, see the babel.config.json for how it's done with babel/babelify

DougAnderson444 commented 3 years ago

63

genderev commented 3 years ago

Okay, I will try to learn babel :/

RangerMauve commented 3 years ago

Looking into this now. 😁 At the very least it should be building the bundle out of the box.

RangerMauve commented 3 years ago

Try the latest Master branch or v2.8.0. I removed the geut sodum-js fork since apparently sodium-javascript should be working correctly now.

genderev commented 3 years ago

The updated README is good! Thanks for all the help!