背景
我完全是BuckleScript的初学者,虽然我以前下载过带有npm的包,但我从来没有写过一个库。
目标:使用npm在我的项目中安装新的包本地包
我试图在JavaScript中封装一些服务工作者api。我从一个文件bs-service-worker/src/ExtenableEvent.re开始,如下所示
type _extendableEvent('a);
type extendableEvent_like('a) = Dom.event_like(_extendableEvent('a));
type extendableEvent = extendableEvent_like(Dom._baseClass);
[@bs.send] external waitUntil: (extendableEvent, Js.Promise.t('a)) => unit
= "waitUntil";这将像预期的那样编译和生成ExtendableEvent.bs.js。
但是现在,我想通过创建一个新的npm项目并在本地导入我所拥有的来测试我到目前为止所拥有的。我创建了一个新的同级目录并执行了一个npm install ../bs-service-worker。这是成功的,然后我在我的新BuckleScript项目上做了一个明智的检查。这也成功了。
问题:打开我的模块会导致错误
当我在新项目中将open ExtendableEvent;添加到Demo.re时,会出现以下错误:
We've found a bug for you!
/home/el/workbench/bucklescript/bs-service-worker-examples/src/Demo.re 11:6-20
9 │
10 │ /**/
11 │ open ExtendableEvent;
12 │
13 │ /*
The module or file ExtendableEvent can't be found.
- If it's a third-party dependency:
- Did you list it in bsconfig.json?
- Did you run `bsb` instead of `bsb -make-world`
(latter builds third-parties)?
- Did you include the file's directory in bsconfig.json? 我试过的
npm run build命令确实是npx bsb -make-world。更多代码:
B-服务-worker/bs-config.json
{
"name": "bs-service-worker",
"version": "0.1.0",
"sources": {
"dir" : "src",
"subdirs" : true,
"public": "all"
},
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [
],
"warnings": {
"error" : "+101"
},
"namespace": true,
"refmt": 3
}B-服务-工作者-示例/bsconfig.json
{
"name": "bs-service-worker-examples",
"version": "0.1.0",
"sources": {
"dir" : "src",
"subdirs" : true
},
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [
"bs-service-worker",
"bs-fetch",
],
"warnings": {
"error" : "+101"
},
"namespace": true,
"refmt": 3
}B-服务-工人-示例/Package.json
{
"name": "bs-service-worker-examples",
"version": "0.0.1",
"scripts": {
"build": "npx bsb -make-world",
"start": "npx bsb -make-world -w",
"clean": "npx bsb -clean-world"
},
"keywords": [
"BuckleScript"
],
"author": "Eleanor (https://webbureaucrat.bitbucket.io)",
"license": "MIT",
"devDependencies": {
"bs-platform": "^7.3.2"
},
"dependencies": {
"bs-fetch": "^0.6.1",
"bs-service-worker": "file:../bs-service-worker"
}
}容易复制的问题
最快的复制方法是分叉这个储存库,并尝试将其添加为本地npm依赖项。
发布于 2020-06-15 20:35:00
问题似乎在于库的"namespace": true中有bsconfig.json,它将所有模块包装在一个命名空间模块中,并根据name字段生成一个愚蠢的名称。在这种情况下,我认为它将是BsServiceWorker。
您可以删除该设置,或者将其设置为false,但是名称空间是一个好主意,可以避免来自不同库或您自己的应用程序的模块之间的冲突,因此我建议将其设置为一个自定义的、合理的名称。例如:
"namespace": "ServiceWorker"然后,您可以在使用者项目中使用以下方法打开ExtendableEvent:
open ServiceWorker.ExtendableEvent;有关更多细节,请参见字段。
https://stackoverflow.com/questions/62395558
复制相似问题