首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可以在没有捆绑器的情况下加载reasonml es6模块吗

可以在没有捆绑器的情况下加载reasonml es6模块吗
EN

Stack Overflow用户
提问于 2020-02-20 00:18:39
回答 1查看 218关注 0票数 1

我正在尝试使用我的VSCODDE肝服务器:https://github.com/ritwickdey/vscode-live-server进行开发,而不需要运行(parceljs将是我的最爱,因为它有热加载,但它与reasonml有问题)。

这几乎可以工作,但是bucklescript编译器希望node-module在路径上,看起来绑定器会找到它们,但如果以这种方式加载,就不会:

es5index.html

代码语言:javascript
复制
<!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>

这是我得到的错误:

代码语言:javascript
复制
ncaught TypeError: Failed to resolve module specifier "react". Relative references must start with either "/", "./", or "../".

这是意料之中的,因为BSB在

App.bs.js

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
// 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"
  ]
}
EN

回答 1

Stack Overflow用户

发布于 2020-02-28 08:29:46

看起来BuckleScript不能使用es6-global导入外部JavaScript模块,包括React。The relevant GitHub issue is here

问题是BuckleScript目前无法知道"react"应该解析到的JavaScript文件的路径。BuckleScript知道它编译的模块的路径,所以它们工作得很好。但是它对外部变量一无所知,所以它会按原样输出它们的路径。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60304777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档