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

"Building a bundle for Browsers" section of README missing critical steps #84

Closed JamesTheAwesomeDude closed 2 years ago

JamesTheAwesomeDude commented 3 years ago

When trying to build a JS file for use in a simple webpage as per the instructions:

$ git clone git@github.com:datproject/sdk.git && cd sdk
Cloning into 'sdk'...
remote: Enumerating objects: 174, done.
remote: Counting objects: 100% (174/174), done.
remote: Compressing objects: 100% (122/122), done.
remote: Total 740 (delta 95), reused 115 (delta 51), pack-reused 566
Receiving objects: 100% (740/740), 170.42 KiB | 612.00 KiB/s, done.
Resolving deltas: 100% (443/443), done.
$ npm run build

> hyper-sdk@3.0.7 build /tmp/hyper-sdk
> cross-env BABEL_DISABLE_CACHE=1 browserify -t [ babelify --global ] --standalone hyperSDK index.js > hyper-sdk-bundle.js

sh: cross-env: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! hyper-sdk@3.0.7 build: `cross-env BABEL_DISABLE_CACHE=1 browserify -t [ babelify --global ] --standalone hyperSDK index.js > hyper-sdk-bundle.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the hyper-sdk@3.0.7 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2021-04-09T23_54_32_216Z-debug.log
$ cat ~/.npm/_logs/2021-04-09T23_54_32_216Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'build' ]
2 info using npm@6.14.10
3 info using node@v12.20.1
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle hyper-sdk@3.0.7~prebuild: hyper-sdk@3.0.7
6 info lifecycle hyper-sdk@3.0.7~build: hyper-sdk@3.0.7
7 verbose lifecycle hyper-sdk@3.0.7~build: unsafe-perm in lifecycle true
8 verbose lifecycle hyper-sdk@3.0.7~build: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/tmp/hyper-sdk/node_modules/.bin:/home/user/.local/bin:/home/user/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
9 verbose lifecycle hyper-sdk@3.0.7~build: CWD: /tmp/hyper-sdk
10 silly lifecycle hyper-sdk@3.0.7~build: Args: [
10 silly lifecycle   '-c',
10 silly lifecycle   'cross-env BABEL_DISABLE_CACHE=1 browserify -t [ babelify --global ] --standalone hyperSDK index.js > hyper-sdk-bundle.js'
10 silly lifecycle ]
11 info lifecycle hyper-sdk@3.0.7~build: Failed to exec build script
12 verbose stack Error: hyper-sdk@3.0.7 build: `cross-env BABEL_DISABLE_CACHE=1 browserify -t [ babelify --global ] --standalone hyperSDK index.js > hyper-sdk-bundle.js`
12 verbose stack spawn ENOENT
12 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18)
12 verbose stack     at ChildProcess.emit (events.js:314:20)
12 verbose stack     at maybeClose (internal/child_process.js:1022:16)
12 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
13 verbose pkgid hyper-sdk@3.0.7
14 verbose cwd /tmp/hyper-sdk
15 verbose Linux 5.10.18-100.fc32.x86_64
16 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "build"
17 verbose node v12.20.1
18 verbose npm  v6.14.10
19 error code ELIFECYCLE
20 error syscall spawn
21 error file sh
22 error errno ENOENT
23 error hyper-sdk@3.0.7 build: `cross-env BABEL_DISABLE_CACHE=1 browserify -t [ babelify --global ] --standalone hyperSDK index.js > hyper-sdk-bundle.js`
23 error spawn ENOENT
24 error Failed at the hyper-sdk@3.0.7 build script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]

What step are the instructions missing? I'm happy to send a PR to fix the documentation.

JamesTheAwesomeDude commented 3 years ago

Though, more generally, I suspect that those instructions are untested or incomplete, as pushing through that error yielded more:

$ npm install cross-env
npm notice created a lockfile as package-lock.json. You should commit this file.
+ cross-env@7.0.3
added 7 packages from 5 contributors and audited 7 packages in 1.676s
found 0 vulnerabilities

$ npm run build

> hyper-sdk@3.0.7 build /tmp/sdk
> cross-env BABEL_DISABLE_CACHE=1 browserify -t [ babelify --global ] --standalone hyperSDK index.js > hyper-sdk-bundle.js

events.js:291
      throw er; // Unhandled 'error' event
      ^

Error: spawn browserify ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
    at onErrorNT (internal/child_process.js:470:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
    at onErrorNT (internal/child_process.js:470:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn browserify',
  path: 'browserify',
  spawnargs: [
    '-t',
    '[',
    'babelify',
    '--global',
    ']',
    '--standalone',
    'hyperSDK',
    'index.js'
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hyper-sdk@3.0.7 build: `cross-env BABEL_DISABLE_CACHE=1 browserify -t [ babelify --global ] --standalone hyperSDK index.js > hyper-sdk-bundle.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the hyper-sdk@3.0.7 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2021-04-10T00_06_01_615Z-debug.log
$ cat ~/.npm/_logs/2021-04-10T00_06_01_615Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'build' ]
2 info using npm@6.14.10
3 info using node@v12.20.1
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle hyper-sdk@3.0.7~prebuild: hyper-sdk@3.0.7
6 info lifecycle hyper-sdk@3.0.7~build: hyper-sdk@3.0.7
7 verbose lifecycle hyper-sdk@3.0.7~build: unsafe-perm in lifecycle true
8 verbose lifecycle hyper-sdk@3.0.7~build: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/tmp/sdk/node_modules/.bin:/home/user/.local/bin:/home/user/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
9 verbose lifecycle hyper-sdk@3.0.7~build: CWD: /tmp/sdk
10 silly lifecycle hyper-sdk@3.0.7~build: Args: [
10 silly lifecycle   '-c',
10 silly lifecycle   'cross-env BABEL_DISABLE_CACHE=1 browserify -t [ babelify --global ] --standalone hyperSDK index.js > hyper-sdk-bundle.js'
10 silly lifecycle ]
11 silly lifecycle hyper-sdk@3.0.7~build: Returned: code: 1  signal: null
12 info lifecycle hyper-sdk@3.0.7~build: Failed to exec build script
13 verbose stack Error: hyper-sdk@3.0.7 build: `cross-env BABEL_DISABLE_CACHE=1 browserify -t [ babelify --global ] --standalone hyperSDK index.js > hyper-sdk-bundle.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:314:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:314:20)
13 verbose stack     at maybeClose (internal/child_process.js:1022:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
14 verbose pkgid hyper-sdk@3.0.7
15 verbose cwd /tmp/sdk
16 verbose Linux 5.10.18-100.fc32.x86_64
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "build"
18 verbose node v12.20.1
19 verbose npm  v6.14.10
20 error code ELIFECYCLE
21 error errno 1
22 error hyper-sdk@3.0.7 build: `cross-env BABEL_DISABLE_CACHE=1 browserify -t [ babelify --global ] --standalone hyperSDK index.js > hyper-sdk-bundle.js`
22 error Exit status 1
23 error Failed at the hyper-sdk@3.0.7 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
JamesTheAwesomeDude commented 3 years ago

It appears that you have to run npm install after cd sdk; only then does it work correctly.

I will send a PR with this shortly if needed.

RangerMauve commented 3 years ago

Yeah, navigating to the sdk folder and running npm install before an npm build is necessary.

A PR with clarification in the README would be much appreciated.

RangerMauve commented 2 years ago

I think the latest version of the README contains this step now. Thank you for opening the issue and working it out!