Jense5 / electron-ad-blocker

Blocks advertisements in an electron browser window
Mozilla Public License 2.0
53 stars 8 forks source link

Rebuilding ad-block fails #3

Closed hawkins closed 7 years ago

hawkins commented 7 years ago

Hey, not sure if this is an ad-block specific problem or what but I figured I'd ask you here.

Following your instructions in the readme, I've received the following error:

$ electron-rebuild -f -w ad-block 
✖ Rebuild Failed
An unhandled error occurred inside electron-rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@3.6.0
gyp info using node@7.8.0 | darwin | x64
gyp info spawn /usr/bin/python
gyp info spawn args [ '/Users/hawkins/git/twitch-flow/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/hawkins/git/twitch-flow/node_modules/ad-block/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/hawkins/git/twitch-flow/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/hawkins/.electron-gyp/.node-gyp/iojs-1.6.6/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/hawkins/.electron-gyp/.node-gyp/iojs-1.6.6',
gyp info spawn args   '-Dnode_gyp_dir=/Users/hawkins/git/twitch-flow/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=iojs.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/hawkins/git/twitch-flow/node_modules/ad-block',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CXX(target) Release/obj.target/ad-block/addon.o
Apple LLVM version 8.1.0 (clang-802.0.41)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name addon.cc -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 278.4 -v -dwarf-column-info -debug-info-kind=standalone -dwarf-version=2 -debugger-tuning=lldb -coverage-file /Users/hawkins/git/twitch-flow/node_modules/ad-block/build/Release/obj.target/ad-block/addon.o -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0 -dependency-file ./Release/.deps/Release/obj.target/ad-block/addon.o.d.raw -MT Release/obj.target/ad-block/addon.o -D NODE_GYP_MODULE_NAME=ad-block -D USING_UV_SHARED=1 -D USING_V8_SHARED=1 -D V8_DEPRECATION_WARNINGS=1 -D _DARWIN_USE_64_BIT_INODE=1 -D _LARGEFILE_SOURCE -D _FILE_OFFSET_BITS=64 -D BUILDING_NODE_EXTENSION -I /Users/hawkins/.electron-gyp/.node-gyp/iojs-1.6.6/include/node -I /Users/hawkins/.electron-gyp/.node-gyp/iojs-1.6.6/src -I /Users/hawkins/.electron-gyp/.node-gyp/iojs-1.6.6/deps/uv/include -I /Users/hawkins/.electron-gyp/.node-gyp/iojs-1.6.6/deps/v8/include -I ../. -I ../node_modules/bloom-filter-cpp -I ../node_modules/hashset-cpp -stdlib=libc++ -stdlib=libc++ -Os -Wall -Wendif-labels -W -Wno-unused-parameter -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/hawkins/git/twitch-flow/node_modules/ad-block/build -ferror-limit 19 -fmessage-length 0 -stack-protector 1 -fblocks -fno-rtti -fno-threadsafe-statics -fobjc-runtime=macosx-10.9.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o Release/obj.target/ad-block/addon.o -x c++ ../addon.cc
clang -cc1 version 8.1.0 (clang-802.0.41) default target x86_64-apple-darwin16.5.0
ignoring nonexistent directory "/Users/hawkins/.electron-gyp/.node-gyp/iojs-1.6.6/include/node"
ignoring nonexistent directory "../node_modules/bloom-filter-cpp"
ignoring nonexistent directory "../node_modules/hashset-cpp"
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
 /Users/hawkins/.electron-gyp/.node-gyp/iojs-1.6.6/src
 /Users/hawkins/.electron-gyp/.node-gyp/iojs-1.6.6/deps/uv/include
 /Users/hawkins/.electron-gyp/.node-gyp/iojs-1.6.6/deps/v8/include
 ../.
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
In file included from ../addon.cc:7:
In file included from ../././ad_block_client_wrap.h:12:
In file included from ../././ad_block_client.h:9:
../././filter.h:12:10: fatal error: 'BloomFilter.h' file not found
#include "BloomFilter.h"
         ^
1 error generated.
make: *** [Release/obj.target/ad-block/addon.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/hawkins/git/twitch-flow/node_modules/node-gyp/lib/build.js:285:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:194:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Darwin 16.5.0
gyp ERR! command "/usr/local/bin/node" "/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/node_modules/.bin/node-gyp" "rebuild" "--target=1.6.6" "--arch=x64" "--dist-url=https://atom.io/download/electron" "--build-from-source"
gyp ERR! cwd /Users/hawkins/git/twitch-flow/node_modules/ad-block
gyp ERR! node -v v7.8.0
gyp ERR! node-gyp -v v3.6.0
gyp ERR! not ok 

Failed with exit code: 1

This repeats another time.

System

I'm running this on a MacBook Pro running MacOS 10.12.4 , with Xcode installed for node-gyp to work.

Repro

  1. Install electron-ad-blocker
  2. Add to electron main.js
  3. Install Xcode
  4. Run your rebuild instruction command

Any ideas whats going on?

Jense5 commented 7 years ago

Not really sure what's the problem, as I am unable to reproduce it. Have you tried removing node-modules and install & build again? I have been in situations where this just solved the rebuild issues.

$ npm install -g electron-rebuild
$ rm -rf node_modules
$ npm install
$ electron-rebuild -f -w ad-block
hawkins commented 7 years ago

Embarrassingly enough, deleting node_modules and reinstalling everything fixed that particular error. However, I'm now presented with a missing path error and I can't tell where it's coming from:

$ ./node_modules/.bin/electron-rebuild -f -w ad-block
✖ Rebuild Failed
An unhandled error occurred inside electron-rebuild
Path must be a string. Received undefined

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.resolve (path.js:1146:7)
    at _callee2$ (/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/lib/rebuild.js:306:67)
    at tryCatch (/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/node_modules/regenerator-runtime/runtime.js:63:40)
    at Generator.invoke [as _invoke] (/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/node_modules/regenerator-runtime/runtime.js:337:22)
    at Generator.prototype.(anonymous function) [as next] (/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/node_modules/regenerator-runtime/runtime.js:96:21)
    at tryCatch (/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/node_modules/regenerator-runtime/runtime.js:63:40)
    at Generator.invoke [as _invoke] (/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/node_modules/regenerator-runtime/runtime.js:279:24)
    at Generator.prototype.(anonymous function) [as next] (/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/node_modules/regenerator-runtime/runtime.js:96:21)
    at Generator.tryCatcher (/Users/hawkins/git/twitch-flow/node_modules/bluebird/js/release/util.js:16:23)
    at PromiseSpawn._promiseFulfilled (/Users/hawkins/git/twitch-flow/node_modules/bluebird/js/release/generators.js:97:49)
    at Promise._settlePromise (/Users/hawkins/git/twitch-flow/node_modules/bluebird/js/release/promise.js:574:26)
    at Promise._settlePromise0 (/Users/hawkins/git/twitch-flow/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/hawkins/git/twitch-flow/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/Users/hawkins/git/twitch-flow/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/Users/hawkins/git/twitch-flow/node_modules/bluebird/js/release/async.js:143:10)
Jense5 commented 7 years ago

Hmm, I just checked the source code of electron-rebuild and I think the node-modules path is missing for some reason. Can you try to add the --module-dir option to the path of the node_modules folder? You might have to reinstall the module first like before, not sure though.

$ npm install -g electron-rebuild
$ rm -rf node_modules
$ npm install
$ electron-rebuild -f -w ad-block --module-dir=node_modules

Please post another stack trace if it doesn't work. Also, are you running electron-rebuild as a global command or as a dev dependency? I always run it as a dev dependency and it just works, so maybe this is because it is the global installation that causes an undefined path to node-modules. Hope this extra option fixes the issue! If it doesn't and you want to try it as a dev dependency (like I do) - run this script (and this one works on my macbook pro, same configuration).

$ npm install --save-dev electron-rebuild
$ rm -rf node_modules
$ npm install
$ ./node_modules/.bin/electron-rebuild -f -w ad-block
hawkins commented 7 years ago

Looks like module-dir is assumed to be the current directory, since it checks for a package.json in the specified folder. Here's the result of passing module-dir:

$ ./node_modules/.bin/electron-rebuild -f -w ad-block --module-dir=node_modules
✖ Rebuild Failed
An unhandled error occurred inside electron-rebuild
ENOENT: no such file or directory, open '/Users/hawkins/git/twitch-flow/node_modules/package.json'

Error: ENOENT: no such file or directory, open '/Users/hawkins/git/twitch-flow/node_modules/package.json'

I've tried specifying the current directory to be sure:

$ ./node_modules/.bin/electron-rebuild -f -w ad-block --module-dir=. 
✖ Rebuild Failed
An unhandled error occurred inside electron-rebuild
Path must be a string. Received undefined

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.resolve (path.js:1146:7)
    at _callee2$ (/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/lib/rebuild.js:306:67)
    at tryCatch (/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/node_modules/regenerator-runtime/runtime.js:63:40)
    at Generator.invoke [as _invoke] (/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/node_modules/regenerator-runtime/runtime.js:337:22)
    at Generator.prototype.(anonymous function) [as next] (/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/node_modules/regenerator-runtime/runtime.js:96:21)
    at tryCatch (/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/node_modules/regenerator-runtime/runtime.js:63:40)
    at Generator.invoke [as _invoke] (/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/node_modules/regenerator-runtime/runtime.js:279:24)
    at Generator.prototype.(anonymous function) [as next] (/Users/hawkins/git/twitch-flow/node_modules/electron-rebuild/node_modules/regenerator-runtime/runtime.js:96:21)
    at Generator.tryCatcher (/Users/hawkins/git/twitch-flow/node_modules/bluebird/js/release/util.js:16:23)
    at PromiseSpawn._promiseFulfilled (/Users/hawkins/git/twitch-flow/node_modules/bluebird/js/release/generators.js:97:49)
    at Promise._settlePromise (/Users/hawkins/git/twitch-flow/node_modules/bluebird/js/release/promise.js:574:26)
    at Promise._settlePromise0 (/Users/hawkins/git/twitch-flow/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/hawkins/git/twitch-flow/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/Users/hawkins/git/twitch-flow/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/Users/hawkins/git/twitch-flow/node_modules/bluebird/js/release/async.js:143:10)

Also so we're clear, I'm also using this as a dev-dependency.

I've followed the exact steps you provided (installing as dev dep, remove node_modules, reinstall all modules, rebuild) for my previous comment and again for this comment, but it yielded the same error and stacktrace.

Can you tell me what version of electron-rebuild you have installed? I'm wondering if this has changed recently; I'm using 1.5.7

Jense5 commented 7 years ago

Sorry for late response. Have you already found a solution for this?

I am also using electron-rebuild v1.5.7.

hawkins commented 7 years ago

No, I was not yet able to find a solution.

Unfortunately, my schedule won't allow much time to debug this for a few weeks so I figure it may be best to close this issue, since it likely isn't truly an issue of electron-ad-blocker's in the first place. I'll leave closing up to your discretion though, as other users may run into this issue in the future.

When I manage to come back to this issue, I'll be sure to leave a comment with the results of next efforts. Thanks so much for your help so far, though!

Jense5 commented 7 years ago

Allright, I'll close it for now but I will also try to solve this when I find the time. Thanks for the report!

cjroebuck commented 7 years ago

Hey @Jense5, @hawkins I'm also seeing the same 'Path must be a String. received undefined' error. I know it's not really a problem with your project but any help would be appreciated!

It seems to be because of this line in rebuild.js of electron-rebuild project.

The .find((file) => file !== '.node' && file.endsWith('.node'))); returns undefined because there is no *.node file in that directory.

If you run it with DEBUG=electron-rebuild ./node_modules/.bin/electron-rebuild -f -w ad-block --module-dir=. you can see what your output is and compare.

These are the files/directories I see in that directory (node_modules/cppunitlite/build/Release), the last debug line before it blows up:

electron-rebuild testing files [ '.deps', '.forge-meta', 'CppUnitLite.a', 'obj.target', 'test' ] +0ms

Now I have managed to hack my way around this to get it working by simply checking the result of the .find before passing it into the path.resolve call:

        let np = (yield fs.readdir(path.resolve(modulePath, 'build/Release'))).find((file) => file !== '.node' && file.endsWith('.node'));
        d('result of find for .node file', np);
        if(np){
            const nodePath = path.resolve(modulePath, 'build/Release', (yield fs.readdir(path.resolve(modulePath, 'build/Release')))
                .find((file) => file !== '.node' && file.endsWith('.node')));
            const abiPath = path.resolve(modulePath, `bin/${process.platform}-${this.arch}-${this.ABI}`);
            if (yield fs.exists(nodePath)) {
                d('found .node file', nodePath);
                d('copying to prebuilt place:', abiPath);
                yield fs.mkdirs(abiPath);
                yield fs.copy(nodePath, path.resolve(abiPath, `${moduleName}.node`));
            }
        }
        this.lifecycle.emit('module-done');
Jense5 commented 7 years ago

Thanks for the info. What version of electron are you using? It looks like I am able to reproduce the issue with electron v1.7.1-beta, but any v1.6.x is working. Might be the same error as described in issue #4.