首页 > 解决方案 > 如何使用本地包中的原因模块

问题描述

我正在寻找一种从我的 Reason React 应用程序(名为 ApplicationA)中使用本地包(名为 bs-package)的方法。

bs-package 在 src 文件夹中有一个名为 ModuleA.re 的文件:

let greet_me = (me) => Js.log("Hello, " ++ me ++ "!");

在 ApplicationA 中,我做了:

npm install /path/to/bs-package

在 node_modules bs-package 现在显示为符号链接。

然后在 bsconfig 中将 bs-package 添加到 bs-dependencies

"bs-dependencies": [
    "reason-react",
    "bs-package",
],

然后在 ApplicationA 中运行 make world

bsb -make-world 

现在在我的 Reason React 应用程序中

ModuleA.greet_me("John");

给我

未绑定模块 ModuleA

我错过了什么?

编辑

这是 bs-package 的配置文件

它是用

bsb -init bs-package -theme basic-reson

bsconfig.json

{
    "name": "bs-pacakge",
    "version": "0.1.0",
    "sources": {
        "dir" : "src",
        "subdirs" : true
    },
    "package-specs": {
        "module": "commonjs",
        "in-source": true
    },
    "suffix": ".bs.js",
    "bs-dependencies": [

    ],
    "warnings": {
        "error" : "+101"
    },
    "namespace": true,
    "refmt": 3
}

包.json

{
    "name": "bs-pacakge",
    "version": "0.1.0",
    "scripts": {
        "build": "bsb -make-world",
        "start": "bsb -make-world -w",
        "clean": "bsb -clean-world"
    },
    "keywords": [
        "BuckleScript"
    ],
    "author": "",
    "license": "MIT",
    "devDependencies": {
        "bs-platform": "^5.0.6"
    }
}

正如建议的那样, bs-package 是命名空间的,所以这应该可以工作

BsPackage.ModuleA.greet_me("name")

但是出现同样的错误

未绑定模块 BsPackage

标签: bucklescriptbsb

解决方案


显然这个错误来自我的 bs 平台版本。我刚刚从 6.2.1 版切换到 7.0.1 版,现在一切正常(我在 Windows 上)。


推荐阅读