kabiroberai / node-swift

Create Node modules in Swift
MIT License
492 stars 16 forks source link

Error running example #29

Closed nickpwhite closed 4 months ago

nickpwhite commented 4 months ago

Hi there! I'm trying to run the example to get started with this package, and running into some issues. Can you help point me in the right direction? Thanks in advance!

Here are the steps I've followed:

  1. git clone git@github.com:kabiroberai/node-swift.git && cd node-swift
  2. npm install <-- This succeeds
  3. cd example
  4. npm install

The last step fails with an error:

/Users/nick/src/node-swift/example/node_modules/node-swift/Package.swift:4:8: error: no such module 'CompilerPluginSupport'

I've also tried to build the projects in XCode, and node-swift builds successfully, but example fails with a bunch of errors like this (for various node APIs):

Undefined symbol: _napi_acquire_threadsafe_function

I'm on an M3 Macbook Pro running macOS Sonoma 14.4.

Full backtrace:

+ nick :: ~/src/node-swift/example → main % npm install

> node-swift-example@1.0.0 install
> node-swift rebuild

warning: could not determine XCTest paths: terminated(1): /usr/bin/xcrun --sdk macosx --show-sdk-platform-path output:
    xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
    xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'

[2/2] Initializing...
warning: could not determine XCTest paths: terminated(1): /usr/bin/xcrun --sdk macosx --show-sdk-platform-path output:
    xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
    xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'

error: Invalid manifest (compiled with: ["/Library/Developer/CommandLineTools/usr/bin/swiftc", "-vfsoverlay", "/var/folders/_n/l59mjf217n7cm06f8_5xnn880000gn/T/TemporaryDirectory.kffxYC/vfs.yaml", "-L", "/Library/Developer/CommandLineTools/usr/lib/swift/pm/ManifestAPI", "-lPackageDescription", "-Xlinker", "-rpath", "-Xlinker", "/Library/Developer/CommandLineTools/usr/lib/swift/pm/ManifestAPI", "-target", "arm64-apple-macosx13.0", "-sdk", "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk", "-swift-version", "5", "-I", "/Library/Developer/CommandLineTools/usr/lib/swift/pm/ManifestAPI", "-sdk", "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk", "-package-description-version", "5.9.0", "/Users/nick/src/node-swift/example/node_modules/node-swift/Package.swift", "-Xfrontend", "-disable-implicit-concurrency-module-import", "-Xfrontend", "-disable-implicit-string-processing-module-import", "-o", "/var/folders/_n/l59mjf217n7cm06f8_5xnn880000gn/T/TemporaryDirectory.yKuYZh/node-swift-manifest"])
/Users/nick/src/node-swift/example/node_modules/node-swift/Package.swift:4:8: error: no such module 'CompilerPluginSupport'
import CompilerPluginSupport
       ^
/Users/nick/src/node-swift/lib/builder.js:259
                throw new Error(`swift build exited with status ${result.status}`);
                      ^

Error: swift build exited with status 1
    at Object.<anonymous> (/Users/nick/src/node-swift/lib/builder.js:259:23)
    at Generator.next (<anonymous>)
    at /Users/nick/src/node-swift/lib/builder.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/nick/src/node-swift/lib/builder.js:4:12)
    at Object.build (/Users/nick/src/node-swift/lib/builder.js:60:12)
    at /Users/nick/src/node-swift/lib/cli.js:61:23
    at Generator.next (<anonymous>)
    at /Users/nick/src/node-swift/lib/cli.js:32:71
    at new Promise (<anonymous>)

Node.js v22.3.0
npm error code 1
npm error path /Users/nick/src/node-swift/example
npm error command failed
npm error command sh -c node-swift rebuild
npm error A complete log of this run can be found in: /Users/nick/.npm/_logs/2024-07-17T00_36_46_849Z-debug-0.log
kabiroberai commented 4 months ago

Seems like your command line is picking up the wrong swiftc. You might need to reset the path to your developer directory

sudo xcode-select --reset

once you do that, try running npm install again.

nickpwhite commented 4 months ago

Awesome, that worked! Thank you so much! Not sure how that got messed up 🤔