简体   繁体   English

无法导入多于一级的模块

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

I'm working on a browser app and am using the below method to import modules as needed.我正在开发浏览器应用程序,并根据需要使用以下方法导入模块。 Unfortunately any modules imported at the 'second level' or deeper treat the asterisk '*' as an unexpected token.不幸的是,在“第二级”或更深层次导入的任何模块都将星号“*”视为意外标记。 It's been a few years since my last JavaScript work and am unsure what I'm doing wrong as much has changed and is new to me.自从我上一次 JavaScript 工作以来已经有几年了,我不确定我做错了什么,因为它已经改变了很多,对我来说是新的。

Below is a minimum example that encounters the issue.以下是遇到此问题的最小示例。 The structure of each module is to emulate C# classes with public, private, and static objects and almost entirely remove the need to type 'this.'每个模块的结构是用公共、私有和 static 对象模拟 C# 类,几乎完全不需要键入“this”。 over and over and over again as is the.js way of doing things.一遍又一遍,就像 .js 做事的方式一样。

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


It turned out the issue was due to a broken line comment throwing off the system.事实证明,问题是由于断线评论导致系统崩溃。 Always look at the previous line for 'Unexpected' errors...始终查看上一行是否有“意外”错误...

I didn't notice this due to how VS Code's Default theme, visually styles code comments and hyperlinks the same.我没有注意到这一点,因为 VS Code 的默认主题,视觉上 styles 代码注释和超链接相同。 Specifically both lines look like the same green text despite one being a comment and the other not.具体来说,尽管一条是注释而另一条不是,但这两行看起来都像相同的绿色文本。

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