/ / कोटलिन में हैलो वर्ल्ड कोटलीन के साथ असफल होना परिभाषित नहीं है - जावास्क्रिप्ट, इंटलिज-विचार, कोटलिन

KotlinJS में हैलो वर्ल्ड कोटलिन के साथ असफलता परिभाषित नहीं है - जावास्क्रिप्ट, इंटेलिज-विचार, कोटलिन

मेरे पास एक कोटलिन फ़ाइल है जिसे कॉल किया गया है Main.kt

package com.ahp.mui

fun main(args: Array<String>) {

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

}

प्रोजेक्ट कोटलिनजेएस परियोजना के रूप में सेटअप है।

एक बार जब मैं संकलित करता हूं, तो मुझे निम्नलिखित फाइलें उत्पन्न होती हैं:

target/production/ahp-mui/ahp-mui.js
target/production/ahp-mui/ahp-mui.js.map
target/production/ahp-mui/ahp-mui.meta.js

मुख्य जनरेट की गई फ़ाइल में है:

(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 रूट निर्देशिका में बैठे:

<html>
<head>

</head>
<body>
TESTING


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

अब वह सेवा कर रहा है index.html IntelliJ के माध्यम से सीधे फ़ाइल (http://localhost:63342/ahp-wui/ahp-mui/index.html?_ijt=n55ajlpfutv6b22n56d59jv1rn), मैं देख रहा हूँ कि Kotlin पैरामैटर परिभाषित नहीं है।

ahp-mui.js:16Uncaught ReferenceError: Kotlin is not defined

क्या मैं यह सही ढंग से कर रहा हूं? क्या मुझे कुछ और आयात करना चाहिए जिसमें लापता शामिल हो Kotlin चर?

उत्तर:

जवाब के लिए 2 № 1

इंटेलीज को कोटलिन मानक पुस्तकालय को बंद करना चाहिए था .js फ़ाइल कहीं। प्रोजेक्ट बनाते समय इसे कॉन्फ़िगर किया गया था। अपने संकलित करने से पहले आपको इसे HTML फ़ाइल में शामिल करना होगा .js फ़ाइल।