Stream: contributing

Topic: typescript interop


view this post on Zulip Richard Feldman (Mar 16 2023 at 14:27):

I just made an example of TypeScript interop via NodeJS - can anyone with npm installed try this out and let me know if it works for you? https://github.com/roc-lang/roc/pull/5146

view this post on Zulip Seth Workman (Mar 16 2023 at 23:18):

Worked for me. I had issues with npm install and node-gyp , ended up just installing each package manually and it worked fine for some reason, same versions even..

Calling Roc...
Called Roc...
Roc says the following: TypeScript said to Roc: Hello from TypeScript! :tada:

view this post on Zulip Richard Feldman (Mar 16 2023 at 23:19):

hm, that's weird - I'm not sure what to make of that :sweat_smile:

view this post on Zulip Richard Feldman (Mar 16 2023 at 23:19):

what OS was this on?

view this post on Zulip Seth Workman (Mar 16 2023 at 23:20):

Mac OS - Ventura 13.0

view this post on Zulip Richard Feldman (Mar 16 2023 at 23:22):

huh! I'm also on macOS :thinking:

view this post on Zulip Richard Feldman (Mar 16 2023 at 23:22):

what versions of node and npm?

view this post on Zulip Seth Workman (Mar 16 2023 at 23:22):

Lets see..
node: v18.12.1
npm: 8.19.3

view this post on Zulip Seth Workman (Mar 16 2023 at 23:26):

I can't seem to recreate it now. I did restart my computer somewhere in debugging the issue, we can just blame it on local env issues .. :sweat_smile:

view this post on Zulip choonkeat (Mar 22 2023 at 03:08):

Seth Workman said:

I had issues with npm install and node-gyp , ended up just installing each package manually and it worked fine for some reason

needed npm install --ignore-scripts to avoid problems

LIBHELLO_FILENAME=$(or $(wildcard libhello.*), libhello)

run-ts: $(LIBHELLO_FILENAME) hello.ts
    npx ts-node hello.ts

run-js: hello.js
    node hello.js

hello.js: $(LIBHELLO_FILENAME) hello.ts
    npx tsc hello.ts

$(LIBHELLO_FILENAME): build demo.c *.roc
    roc build --lib
    npx node-gyp build
    cp addon.d.ts build/Release/

build: node_modules
    npx node-gyp configure

# ignore-scripts is needed otherwise error:
#    ld: library not found for -lhello
#    clang: error: linker command failed with exit code 1 (use -v to see invocation)
node_modules:
    npm install --ignore-scripts

clean:
    rm -rf libhello.dylib build hello.js node_modules

Last updated: Jul 05 2025 at 12:14 UTC