zhangyuang / node-ffi-rs

Implement ffi in Node.js by Rust and NAPI
MIT License
157 stars 6 forks source link

Unexpected character '�' (1:2) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. #69

Closed zhangshijuan closed 1 week ago

zhangshijuan commented 2 weeks ago

我的需求是这样的:我在vscode插件开发中想使用ffi-rs来读取本地的动态库so文件中的方法返回秘钥信息; 当我安装成功ffi-rs后,引入ffi-rs运行报错; 开发环境:node:v20.14.0 Activating extension 'yidong.newcall-plugin' failed: Module parse failed: Unexpected character '�' (1:2) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders (Source code omitted for this binary file).

zhangyuang commented 2 weeks ago

直接在node.js环境中加载ffi-rs,而不是在webpack环境去构建它

zhangshijuan commented 2 weeks ago

大佬那我需要如何修改,是需要添加webpack.config.js的配置嘛

zhangyuang commented 2 weeks ago

...你先搞清楚webpack是干嘛的,使用ffi-rs不需要用到webpack

zhangshijuan commented 2 weeks ago

我的webpack是开发vscode拓展插件中打包扩展插件用的,我是在vscode拓展插件激活时读取插件根据目录下的so文件中方法返回的秘钥,用秘钥去和公钥验签,实现插件激活

zhangyuang commented 2 weeks ago

你根本没搞懂我在说什么。webpack是打包代码的bundle工具,ffi-rs根本不需要打包是node原生模块。你非要用webpack的话自行去搜索相关方案https://webpack.docschina.org/loaders/node-loader/

zhangshijuan commented 1 week ago

image 现在报这个错:Activating extension 'yidong.newcall-plugin' failed: Before calling load, you need to open the file "h:\workeZT\新通话插件\code\code-dev\newCall-plugin-vscode\resources\test.dll" with the open method.大佬再帮看看呢

zhangyuang commented 1 week ago

open的library和load的library不是同一份

zhangshijuan commented 1 week ago

感谢大佬哈哈哈,终于拿到了数据了

zhangyuang commented 1 week ago

另外这里安装ffi-rs只会安装当前平台的二进制文件,如果你的插件需要在多个不同的平台调用。那么你安装的时候需要使用例如如下方案安装指定平台的包

прm i @yuuang/ffi-rs-win32-arm64-msvc --force

完整的平台架构如下

 "optionalDependencies": {
    "@yuuang/ffi-rs-darwin-arm64": "1.0.55",
    "@yuuang/ffi-rs-darwin-x64": "1.0.55",
    "@yuuang/ffi-rs-linux-arm64-gnu": "1.0.55",
    "@yuuang/ffi-rs-linux-arm64-musl": "1.0.55",
    "@yuuang/ffi-rs-linux-x64-gnu": "1.0.55",
    "@yuuang/ffi-rs-linux-x64-musl": "1.0.55",
    "@yuuang/ffi-rs-win32-ia32-msvc": "1.0.55",
    "@yuuang/ffi-rs-win32-x64-msvc": "1.0.55",
    "@yuuang/ffi-rs-win32-arm64-msvc": "1.0.55"
  }
zhangshijuan commented 1 week ago

好的,感谢