首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义KotlinJS中的Hello与Kotlin一起失败

未定义KotlinJS中的Hello与Kotlin一起失败
EN

Stack Overflow用户
提问于 2016-05-30 21:18:17
回答 1查看 1.1K关注 0票数 1

我有一个叫Main.kt的Kotlin文件

代码语言:javascript
复制
package com.ahp.mui

fun main(args: Array<String>) {

    println("...")
    println("Hello World")

}

项目设置为KotlinJS项目。

一旦我点击了编译,我就会看到生成了以下文件:

代码语言:javascript
复制
target/production/ahp-mui/ahp-mui.js
target/production/ahp-mui/ahp-mui.js.map
target/production/ahp-mui/ahp-mui.meta.js

生成的主文件包括:

代码语言:javascript
复制
(function (Kotlin) {
  'use strict';
  var _ = Kotlin.defineRootPackage(null, /** @lends _ */ {
    com: Kotlin.definePackage(null, /** @lends _.com */ {
      ahp: Kotlin.definePackage(null, /** @lends _.com.ahp */ {
        mui: Kotlin.definePackage(null, /** @lends _.com.ahp.mui */ {
          main_kand9s$: function (args) {
            Kotlin.println('...');
            Kotlin.println('Hello World');
          }
        })
      })
    })
  });
  Kotlin.defineModule('ahp-mui', _);
  _.com.ahp.mui.main_kand9s$([]);
}(Kotlin));

现在,我将该文件包含在根目录中的index.html中:

代码语言:javascript
复制
<html>
<head>

</head>
<body>
    TESTING


    <script type="text/javascript" src="target/production/ahp-mui/ahp-mui.js"></script>
</body>
</html>

现在通过IntelliJ (http://localhost:63342/ahp-wui/ahp-mui/index.html?_ijt=n55ajlpfutv6b22n56d59jv1rn)直接提供该Kotlin文件,我看到Kotlin参数没有定义。

代码语言:javascript
复制
ahp-mui.js:16Uncaught ReferenceError: Kotlin is not defined

我做得对吗?我是否应该导入将包括缺失的Kotlin变量的其他内容?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-30 22:34:52

IntelliJ应该在某个地方设置一个Kotlin标准库.js文件。这是在您创建项目时配置的。您必须在编译的.js文件之前将其包含在HTML中。

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

https://stackoverflow.com/questions/37533768

复制
相关文章

相似问题

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