What happened
When compiling a file that imports a native package, collect_modules prints Warning: Could not resolve import 'native' from main.ts and Perry fails to link the executable.
What you expected
Perry resolves the native module correctly.
Minimal reproduction
- Create a native package named
native using perry native init native
- Create a new package in the same folder and install the native dependency using
pnpm add ../native
- Add
main.ts:
// main.ts
import { hello } from "native";
console.log(hello());
- Compile
main.ts using perry compile ./main.ts
Environment
- Perry version: 0.5.891
- Host OS: Windows 11
- Target: native
- Rust toolchain: 1.94.1
- Installed via: winget
Diagnostic output
PS D:\Develop\.test\volt\caller> perry compile ./main.ts
Collecting modules...
Warning: Could not resolve import 'native' from main.ts
Found 1 module(s): 1 native, 0 JavaScript
Generating code...
Wrote object file: main_ts.o
Linking (runtime-only)...
main_ts.o : error LNK2019: 无法解析的外部符号 hello,函数 main 中引用了该符号
main.exe : fatal error LNK1120: 1 个无法解析的外部命令
Error: Linking failed
Anything else
Adding "types": "src/main.ts" or "main": "src/main.ts" to the native package's package.json allows Perry to compile successfully:
PS D:\Develop\.test\volt\caller> perry compile ./main.ts
Collecting modules...
Native library: native (1 FFI functions)
Found 2 module(s): 2 native, 0 JavaScript
Generating code...
Wrote object file: caller_main_ts.o
Wrote object file: native_src_index_ts.o
Linking (runtime-only)...
Building native library: native ...
Finished `release` profile [optimized] target(s) in 0.17s
Wrote executable: main.exe
Binary size: 1.1MB
However, hello() then falls back to its TypeScript implementation:
PS D:\Develop\.test\volt\caller> .\main.exe
Hello, undefined!
What happened
When compiling a file that imports a native package,
collect_modulesprintsWarning: Could not resolve import 'native' from main.tsand Perry fails to link the executable.What you expected
Perry resolves the native module correctly.
Minimal reproduction
nativeusingperry native init nativepnpm add ../nativemain.ts:main.tsusingperry compile ./main.tsEnvironment
Diagnostic output
Anything else
Adding
"types": "src/main.ts"or"main": "src/main.ts"to the native package'spackage.jsonallows Perry to compile successfully:However,
hello()then falls back to its TypeScript implementation: