簡體   English   中英

無法導入多於一級的模塊

[英]Unable to import more than one level of module

我正在開發瀏覽器應用程序,並根據需要使用以下方法導入模塊。 不幸的是,在“第二級”或更深層次導入的任何模塊都將星號“*”視為意外標記。 自從我上一次 JavaScript 工作以來已經有幾年了,我不確定我做錯了什么,因為它已經改變了很多,對我來說是新的。

以下是遇到此問題的最小示例。 每個模塊的結構是用公共、私有和 static 對象模擬 C# 類,幾乎完全不需要鍵入“this”。 一遍又一遍,就像 .js 做事的方式一樣。

內容.js

//Directly attached to the page using <script type="module" src="Content.js"></script>

import * as XRVideo from "../Viewer/Scripts/XRVideo.js"; //This works perfectly

var urlA = "Testing/VideoA.mp4";
var urlB = "Testing/VideoB.mp4";

var arrXRVideos = [];

window.addEventListener("load", (e) =>{
    arrXRVideos.Push(XRVideo.New(urlA));
    arrXRVideos.Push(XRVideo.New(urlB));
});

XRVideo.js

import * as XRScene from "./Core/XRScene.js"; //This throws an Unexpected Token '*' Error
import * as XRSkybox from "./Core/XRSkybox.js";


/* Static */
export const XRStatus = {
    Stopped : 0,
};


/* Instanced */
export function New(videoURL){
    var _isInitialized = false;
    var _url = "";

//#region Pseudo Constructor
    {
        _url = videoUrl;

        _isInitialized = true;
    }
//#endregion

    /* Getters & Setters */
    function GetURL(){
        return _url;
    }

    /* Exposed As Public */
    //Properties can't be directly exposed otherwise they become static...
    return{
        GetURL : GetURL
    }
}


事實證明,問題是由於斷線評論導致系統崩潰。 始終查看上一行是否有“意外”錯誤...

我沒有注意到這一點,因為 VS Code 的默認主題,視覺上 styles 代碼注釋和超鏈接相同。 具體來說,盡管一條是注釋而另一條不是,但這兩行看起來都像相同的綠色文本。

//This is a comment, VS Code shows it as a dirty green.
//I am a code comment

//This is a URL that accidentally didn't get the '//' to turn it into a comment,
//VS Code shows it as a dirty green making it look like a comment.
https://github.com/blah-blah-blah

import * as Bah from "./Foo.js"; //Unexpected token '*'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM