无法导入多于一级的模块

Unable to import more than one level of module

我正在开发浏览器应用程序,并使用以下方法根据需要导入模块。不幸的是,在 'second level' 或更深的位置导入的任何模块都将星号“*”视为意外标记。自从我上一次 JavaScript 工作以来已经有几年了,我不确定我做错了什么,因为很多事情都发生了变化,对我来说是新的。

以下是遇到该问题的最小示例。每个模块的结构都是用 public、私有和静态对象模拟 C# 类,并且几乎完全不需要像 .js 一样一遍又一遍地输入 'this.'做事方式。

Content.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
    }
}


原来这个问题是由于一条断线的评论抛出了系统。始终查看前一行是否有 'Unexpected' 错误...

我没有注意到这一点,因为 VS Code 的默认主题在视觉上使代码注释和超链接的样式相同。具体来说,这两行看起来像是相同的绿色文本,尽管其中一行是评论而另一行不是。

//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 '*'