nrkno/sofie-casparcg-media-scanner

Building instructions are confusing and don't work

dimitry-ishenko opened this issue · 4 comments

The README page says:

This project uses the latest LTS version NodeJS (8), so you need that installed. Get it from: https://nodejs.org/en/.

The latest LTS version is 14 and not 8. Unless "8" refers to V8. So, do I need node 8 (eg, 8.9.4) or 14 (eg 14.15.3)?

Later on:

After this:

  • Clone the repository
  • Run npm install
  • Run npm dev to start the development server

Running npm dev gives an error. But since I am not planning to run the development server and just want to build a production version, I've ignored this error.

Later on:

On Linux

  • npm run build-linux

Running this command inside node:8.9.4 Docker container I get this error:

> scanner@1.6.1 build-linux /opt/scanner
> trash deploy && mkdir deploy && nexe src.index.js -o deploy/scanner -t linux-x64 && node copy-natives.js linux-x64

/opt/scanner/node_modules/resolve-dependencies/lib/node-loader.js:13
const readFile = fs_1.promises.readFile;
                               ^

TypeError: Cannot read property 'readFile' of undefined
    at Object.<anonymous> (/opt/scanner/node_modules/resolve-dependencies/lib/node-loader.js:13:32)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/opt/scanner/node_modules/resolve-dependencies/lib/resolve.js:6:23)
    at Module._compile (module.js:643:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! scanner@1.6.1 build-linux: `trash deploy && mkdir deploy && nexe src.index.js -o deploy/scanner -t linux-x64 && node copy-natives.js linux-x64`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the scanner@1.6.1 build-linux 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!     /root/.npm/_logs/2020-12-21T02_30_20_093Z-debug.log

Running inside node:lts Docker container I get a different error:

> scanner@1.6.1 build-linux /opt/scanner
> trash deploy && mkdir deploy && nexe src.index.js -o deploy/scanner -t linux-x64 && node copy-natives.js linux-x64

ℹ nexe 3.3.7
✔ Downloading pre-built Node.js
✔ Finished in 9.553s

Error: https://github.com/nexe/nexe/releases/download/v3.3.3/linux-x64-14.15.3 is not available, create it using the --build flag

See nexe -h for usage..

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! scanner@1.6.1 build-linux: `trash deploy && mkdir deploy && nexe src.index.js -o deploy/scanner -t linux-x64 && node copy-natives.js linux-x64`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the scanner@1.6.1 build-linux 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!     /root/.npm/_logs/2020-12-21T02_44_23_140Z-debug.log

This looks like a lose-lose situation... 😕

OK so it turns out the latest version of nexe for linux-x64 is 12.16.2. The latest version varies depending on the platform. For example, they have up to 14.15.2 for linux-x86. Totally weird... (just like the rest of nodejs).

The next bit of README says:

The built files will be placed in ./dist, make sure you copy all files into the main CasparCG directory.

Except the files are placed inside deploy directory and not dist.

I've copied the files are out and tried running the resulting scanner binary. Sadly, I was greeted with this error message:

internal/modules/cjs/loader.js:983
  throw err;
  ^

Error: Cannot find module 'mkdirp-promise'
Require stack:
- /home/dimitry/arch/casparcg/build/scanner/nrk/scanner/src/previews.js
- /home/dimitry/arch/casparcg/build/scanner/nrk/scanner/src/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/home/dimitry/arch/casparcg/build/scanner/nrk/scanner/src/previews.js:3:16)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1042:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/dimitry/arch/casparcg/build/scanner/nrk/scanner/src/previews.js',
    '/home/dimitry/arch/casparcg/build/scanner/nrk/scanner/src/index.js'
  ]
}

OK, so cloning master branch instead of the latest release v1.6.1 I am now able to run the scanner. What a trip... 🤯 I hope I never have to take it again.

To summarize, here is my build-scanner script to build scanner inside Docker container:

#!/bin/bash
docker build --tag casparcg/scanner - <<EOF
    FROM node:12.16.2

    WORKDIR /opt
    RUN git clone https://github.com/nrkno/tv-automation-media-scanner.git --depth 1 scanner

    WORKDIR /opt/scanner
    RUN npm install && npm run build-linux
    RUN mv ./deploy /scanner
EOF

And here is the extract-scanner script to extract it from the container:

#!/bin/bash
id=$(docker create casparcg/scanner)
docker cp $id:/scanner .
docker rm -v $id

I hope somebody finds this useful. I s'pose I should post these in the forums.

Could somebody please fix the README.

I have updated the readme with your findings, as well as pinning the node version that nexe tries to build with.
Hopefully this helps

Thanks @Julusian. It works now. I've posted my scripts in the forums as well.