我正在尝试使用我的VSCODDE肝服务器:https://github.com/ritwickdey/vscode-live-server进行开发,而不需要运行(parceljs将是我的最爱,因为它有热加载,但它与reasonml有问题)。
这几乎可以工作,但是bucklescript编译器希望node-module在路径上,看起来绑定器会找到它们,但如果以这种方式加载,就不会:
es5index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<link rel=stylesheet href="./style.css">
<title>Web Data Client</title>
<script src="../src/client/App.bs.js" type=module></script>
</head>
<body>
<div id="index"></div>
</body>
</html>这是我得到的错误:
ncaught TypeError: Failed to resolve module specifier "react". Relative references must start with either "/", "./", or "../".这是意料之中的,因为BSB在
App.bs.js
import * as $$Array from "./../../node_modules/bs-platform/lib/es6/array.js";
import * as Block from "./../../node_modules/bs-platform/lib/es6/block.js";
import * as Curry from "./../../node_modules/bs-platform/lib/es6/curry.js";
import * as React from "react";
import * as Glamor from "./../../node_modules/bs-glamor/src/glamor.js";
import * as Js_exn from "./../../node_modules/bs-platform/lib/es6/js_exn.js";
import * as Js_dict from "./../../node_modules/bs-platform/lib/es6/js_dict.js";
import * as Js_json from "./../../node_modules/bs-platform/lib/es6/js_json.js";
import * as ReactDOMRe from "./../../node_modules/reason-react/src/ReactDOMRe.js";
import * as Caml_option from "./../../node_modules/bs-platform/lib/es6/caml_option.js";
import * as ReasonReact from "./../../node_modules/reason-react/src/ReasonReact.js";
import * as Editor$Webdataclient from "./Editor.bs.js";
import * as Loader$Webdataclient from "./Loader.bs.js";
import * as Mutations$Webdataclient from "./Mutations.bs.js";现在,如果导入来自../node-modules/*文件夹,我想一切都会正常工作
bsconfig.json文件:
// This is the configuration file used by BuckleScript's build system bsb.
// Its documentation lives here: http://bucklescript.github.io/bucklescript/docson/#build-schema.json
{
"name": "webdataclient",
"version": "0.1.0",
"sources": [
{
"dir": "src",
"subdirs": true
}
],
"package-specs": {
"module": "es6-global",
"in-source": true
},
"suffix": ".bs.js",
"namespace": true,
"reason": {
"react-jsx": 2
},
"refmt": 3,
"ppx-flags": [
"graphql_ppx/ppx"
],
"bs-dependencies": [
"reason-react",
"bs-fetch",
"bs-glamor"
]
}发布于 2020-02-28 08:29:46
看起来BuckleScript不能使用es6-global导入外部JavaScript模块,包括React。The relevant GitHub issue is here。
问题是BuckleScript目前无法知道"react"应该解析到的JavaScript文件的路径。BuckleScript知道它编译的模块的路径,所以它们工作得很好。但是它对外部变量一无所知,所以它会按原样输出它们的路径。
https://stackoverflow.com/questions/60304777
复制相似问题