[英]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.