这是我在Visual Studio Code上收到的错误消息。
[ts]文件是CommonJS模块;可以将其转换为ES6模块。
[ts]意外令牌。预期使用构造函数,方法,访问器或属性。
[eslint]解析错误:意外令牌。 模块export =(属性)export =:{ [x:字符串]:任何; 片段:typeof片段; }
这是用于一个名为Snippet的类的[有些人可能会发现它有些长,但建议我显示Snippet内的内容-fyi]:
class Snippet {
/**
* @constructor
* @param {any} fileName - file name.
* @param {any} code - code.
* @param {any} numTags - number of tags.
* @param {any} tags - all tags.
*/
constructor(fileName, code, ...tags) {
this.name = fileName;
this.code = code;
this.tags = tags;
this.lines = code.split(/\r\n|\r|\n/).length;
}
/**
* @function
* @name myFunction
* @param {any} tag - check tag.
* @return {boolean} boolean
*/
hasTag(tagCheck) {
if (this.tags.hasOwnProperty(tagCheck)) {
if (Object.prototype.hasOwnProperty.call(this.tags, tagCheck)) {
return true;
}
else {
return false;
}
}
}
}
我尝试了这4种:
module.exports = {
Snippet:Snippet
};
module.exports = {
Snippet
};
module.exports = {
Snippet:Snippet,
};
module.exports = {
Snippet,
};
我仍然收到与引用相同的错误消息。 有谁知道如何解决这个问题? 在此先感谢您,非常感谢。