Error Unknown file extension ".node" when running test js file #4

Closed
opened 2023-02-23 15:39:12 +00:00 by jsoneaday · 1 comment
jsoneaday commented 2023-02-23 15:39:12 +00:00 (Migrated from github.com)

I was able to build successfully and then created a js file to run but when I do run it gives the error. I run with node test.mjs. My two go files are like this:

package handlers

import (
	"github.com/akshayganeshen/napi-go/js"
)

func MyHandler(env js.Env, this js.Value, args []js.Value) any {
	return "hello"
}
package main

import (
	"keyring/internal/handlers"

	"github.com/akshayganeshen/napi-go/entry"

	"github.com/akshayganeshen/napi-go/js"
)

func init() {
	entry.Export("myHandler", js.AsCallback(handlers.MyHandler))
}

func main() {}
I was able to build successfully and then created a js file to run but when I do run it gives the error. I run with node test.mjs. My two go files are like this: ``` package handlers import ( "github.com/akshayganeshen/napi-go/js" ) func MyHandler(env js.Env, this js.Value, args []js.Value) any { return "hello" } ``` ``` package main import ( "keyring/internal/handlers" "github.com/akshayganeshen/napi-go/entry" "github.com/akshayganeshen/napi-go/js" ) func init() { entry.Export("myHandler", js.AsCallback(handlers.MyHandler)) } func main() {} ```
jsoneaday commented 2023-02-23 16:38:46 +00:00 (Migrated from github.com)

I got further by abandoning es modules and using require. But now its giving error about x86_64 but I'm on M1 Mac.

Error: dlopen(/Users/davidchoi/Work/philabs/keyring/keyring-go/example.node, 0x0001): tried: '/Users/davidchoi/Work/philabs/keyring/keyring-go/example.node' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/davidchoi/Work/philabs/keyring/keyring-go/example.node' (no such file), '/Users/davidchoi/Work/philabs/keyring/keyring-go/example.node' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
    at Module._extensions..node (node:internal/modules/cjs/loader:1243:18)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/Users/davidchoi/Work/philabs/keyring/keyring-go/test.js:1:17)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12) {
  code: 'ERR_DLOPEN_FAILED'
}
I got further by abandoning es modules and using require. But now its giving error about x86_64 but I'm on M1 Mac. ``` Error: dlopen(/Users/davidchoi/Work/philabs/keyring/keyring-go/example.node, 0x0001): tried: '/Users/davidchoi/Work/philabs/keyring/keyring-go/example.node' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/davidchoi/Work/philabs/keyring/keyring-go/example.node' (no such file), '/Users/davidchoi/Work/philabs/keyring/keyring-go/example.node' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')) at Module._extensions..node (node:internal/modules/cjs/loader:1243:18) at Module.load (node:internal/modules/cjs/loader:1037:32) at Module._load (node:internal/modules/cjs/loader:878:12) at Module.require (node:internal/modules/cjs/loader:1061:19) at require (node:internal/modules/cjs/helpers:103:18) at Object.<anonymous> (/Users/davidchoi/Work/philabs/keyring/keyring-go/test.js:1:17) at Module._compile (node:internal/modules/cjs/loader:1159:14) at Module._extensions..js (node:internal/modules/cjs/loader:1213:10) at Module.load (node:internal/modules/cjs/loader:1037:32) at Module._load (node:internal/modules/cjs/loader:878:12) { code: 'ERR_DLOPEN_FAILED' } ```
Sign in to join this conversation.
No description provided.