TooTallNate / NodObjC

The Node.js ⇆ Objective-C bridge

Home Page:http://tootallnate.github.io/NodObjC

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

when electron update to 1.2.1 the NodObjc it does not work

imlliu2005 opened this issue · comments

@TooTallNate
Hi TooTallNate, I have a problem when my electron from 1.1.1 update to 1.2.1 when it use nodobjc call objective-c framework like this:
app threw an error during load

TypeError: error setting argument 0 - writePointer: Buffer instance expected as third argument
at TypeError (native)
at Object.writePointer (/Users/apple/talk/electron-quick-start-master/node_modules/ref/lib/ref.js:742:11)
at Object.set (/Users/apple/talk/electron-quick-start-master/node_modules/ref/lib/ref.js:484:13)
at Object.alloc (/Users/apple/talk/electron-quick-start-master/node_modules/ref/lib/ref.js:516:13)
at Object.proxy as objc_getClassList
at Object.getClassList (/Users/apple/talk/electron-quick-start-master/node_modules/nodobjc/lib/core.js:111:20)
at Object.importFramework (/Users/apple/talk/electron-quick-start-master/node_modules/nodobjc/lib/import.js:321:26)
at Function.framework (/Users/apple/talk/electron-quick-start-master/node_modules/nodobjc/lib/index.js:225:18)
at Object. (/Users/apple/talk/electron-quick-start-master/main.js:14:9)
^C

I need your help,thanks.

This is my code:

var nodobjc = require('nodobjc');
nodobjc.framework('/Users/apple/talk/screenshot.framework');

the error:

appledeMacBook-Pro:electron-quick-start-master apple$ npm start

> electron-quick-start@1.0.0 start /Users/apple/talk/electron-quick-start-master
> electron main.js

App threw an error during load
TypeError: error setting argument 0 - writePointer: Buffer instance expected as third argument
    at TypeError (native)
    at Object.writePointer (/Users/apple/talk/electron-quick-start-master/node_modules/ref/lib/ref.js:742:11)
    at Object.set (/Users/apple/talk/electron-quick-start-master/node_modules/ref/lib/ref.js:484:13)
    at Object.alloc (/Users/apple/talk/electron-quick-start-master/node_modules/ref/lib/ref.js:516:13)
    at Object.proxy [as objc_getClassList] (/Users/apple/talk/electron-quick-start-master/node_modules/ffi/lib/_foreign_function.js:50:22)
    at Object.getClassList (/Users/apple/talk/electron-quick-start-master/node_modules/nodobjc/lib/core.js:111:20)
    at Object.importFramework (/Users/apple/talk/electron-quick-start-master/node_modules/nodobjc/lib/import.js:321:26)
    at Function.framework (/Users/apple/talk/electron-quick-start-master/node_modules/nodobjc/lib/index.js:225:18)
    at Object.<anonymous> (/Users/apple/talk/electron-quick-start-master/main.js:14:9)
    at Module._compile (module.js:541:32)
^C

I ask the same question to the electron master,the give the answer is:
It is probably because nodobjc is not compatible with V8 5.1, sorry we are not able to fix problems of third party modules.

I get the same exception in my app after upgrading Electron from 1.1.3 to 1.2.0 (and presumably also 1.2.1).

Right now we can just stay at 1.1.3 as we don't need any other newer features but I'm guessing this will also be an issue when Node updates V8.

@slaskis I'm looking forward to this problem can be solved, or is about to change another plan, give up nodobjc,This is a very pity。

I'm having the same issue.

Just a note that this is likely not related to the framework @imlliu2005 is using. I get it even when I do $.framework('Cocoa');

@TooTallNate Here is a link to the issue that @imlliu2005 filed on electron. electron/electron#5927

@TooTallNate I'm having same issue too. @trevorlinton found fix for similar error previously- any ideas on quick fix?

My log shows, Uncaught TypeError: error setting argument 0 - writePointer: Buffer instance expected as third argument.

screen shot 2016-06-15 at 10 25 08 pm

Does anyone plan to look at this? As is stands this library is broken for all current and future versions of Node. I will have a look but I am not well versed in C++ to debug in depth. It would be a shame to let this library stagnate as it is an incredibly powerful feature for Node and Electron apps.

From Node.js space - calls to writePointer(buf, offset, ptr) from ref/lib/ref.js where ptr is null throw the error writePointer: Buffer instance expected as third argument.

Has anybody been able to reproduce this issue using vanilla Node.js (as opposed to Electron?). Just trying to narrow things down here.

Seems to work outside Electron fine. This is odd. When I npm install with 5.x and start electron (electron-prebuilt uses 6.1) it works fine. Yet switching to 6.x and performing a fresh npm install we get the above error. Seems more of a packaging issue or a node-gyp issue with ffi or ref and not an API issue with this repo - as in both cases they use the same version of Node.

Not sure if this is helpful but I can reproduce the issue with the following:

11:46:42 $ nvm use 5
Now using node v5.10.1 (npm v3.8.3)
11:46:47 $ npm install
11:47:19 $ node test.js <----------- working
11:47:31 $ nvm use 6
Now using node v6.2.2 (npm v3.9.5)
11:47:35 $ node test.js <----------- working
11:47:40 $ npm rebuild ref
11:47:48 $ node test.js <----------- writePointer error inside Electron

Where test.js boots up Electron and performs an initialisation of examples/EventLoop.js. Running the example without Electron works in all cases.

I think the reason is that node hasn't updated v8 to 5.1+ yet, while Electron has.

At least in node 6.3.0:

$ node -p process.versions
{ http_parser: '2.7.0',
  node: '6.3.0',
  v8: '5.0.71.52',
  uv: '1.9.1',
  zlib: '1.2.8',
  ares: '1.10.1-DEV',
  icu: '57.1',
  modules: '48',
  openssl: '1.0.2h' }

@slaskis I am not so sure why that would be the issue seeing as 5.x running the latest electron-prebuilt is working.

Any info/workaround/fix on this? 😕

const macOS = require('nodobjc');

macOS.framework('Foundation');
macOS.framework('AVFoundation');
❯  node --version && electron --version
v6.3.0
v1.3.3
❯ npm start

> focus@0.1.0 start /Users/matheus/dev/node/focus
> electron .

App threw an error during load
Error: Module version mismatch. Expected 49, got 48.
    at Error (native)
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:167:20)
    at Object.Module._extensions..node (module.js:568:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:167:20)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at bindings (/Users/matheus/dev/node/focus/node_modules/bindings/bindings.js:76:44)

@matheuss , you need to electron-rebuild your modules

@dimatter: just npm i --save electron-rebuild && node_modules/.bin/electron-rebuild? Didn't worked :(

@imlliu2005 @matheuss @slaskis @TooTallNate @greenimpala @kmartinezmedia @atdrago

I haven't been coding for long, so forgive me if this is a little long winded ( I think I have a solution to this issue ):

I'm using Electron v1.4.5 & node v7.0.0 & I'm getting this error:
Error: Module version mismatch. Expected 50, got 51.

In case it helps understand this a little further, I think the 50 in Expected 50, got 51 relates to the following:

cd node_modules/electron/dist/Electron.app/Contents/MacOS
./Electron --abi`
//50

And the 51 in Expected 50, got 51 relates to this:

node -p process.versions
//returns:
{ http_parser: '2.7.0',
  node: '7.0.0',
  v8: '5.4.500.36',
  uv: '1.9.1',
  zlib: '1.2.8',
  ares: '1.10.1-DEV',
  icu: '57.1',
  modules: '51',
  openssl: '1.0.2j' }

So, to get Electron & NodObjC working again, run this in the root of your project directory:

npm rebuild --runtime=electron --target=1.4.5 --disturl=https://atom.io/download/atom-shell --abi=50

The --target you can get from your project, like this:

cd node_modules/electron/dist/Electron.app/Contents/MacOS
./Electron --version
// which for me returns 1.4.5

and the --abi you can get from your project too, like this:

cd node_modules/electron/dist/Electron.app/Contents/MacOS
./Electron --abi`
// which for me returns 50

This worked for me, and I was pretty happy with myself !

Just for completeness, here is the original full error:

App threw an error during load
Error: Module version mismatch. Expected 50, got 51.
    at Error (native)
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:178:20)
    at Object.Module._extensions..node (module.js:583:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:178:20)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at bindings (/Users/rootscript/Github/elm0171-electron145/node_modules/bindings/bindings.js:76:44)

Hope this helps you guys (until Electron & Node get there versions synced)