【发布时间】:2018-07-14 04:27:47
【问题描述】:
过去几天,这个问题一直让我失去理智。
这是我的目录结构:
[src]
|- cmds/
| |- Gh.js
| \- Help.js
|- commands.js
|...
我正在尝试将commands.js 导出的类导入Help.js 和Gh.js(以及我将来可能添加的任何其他文件)。但是,我不断收到错误消息:
class Gh extends _commands.Command {
^
TypeError: Class extends value undefined is not a constructor or null
所有文件都使用 Babel 进行转译,env 设置为 "node": "current" 并使用 wildcard 包。我尝试将其设置为"browser",以查看是否是它过于“高级”的问题,但我得到了一个关于超级函数(或其他东西)的不同错误,我认为这是同一个问题。
这是从commands.js 导出的类:
export class Command {
constructor (msg) {
this.id = msg.author.id
this.msg = msg
}
action () {}
get data () {
return readData().user[this.id]
}
updateUserData (key, val) {
updateUserData(this.id, key, val)
}
sendMsg (data) {
sendMsg(this.msg, data)
}
}
...这里是cmds/Gh.js,这是我尝试将Command 导入的文件之一:
import {Command} from '../commands'
export class Gh extends Command {
constructor (msg) {
super(msg)
this.desc = 'Returns GitHub repository link and exits'
}
action () {
this.sendMsg('GitHub link: https://github.com/owm111/knife-wife')
}
}
我尝试将Command 放入两个cmds/,并且它们运行良好。然而,当它移回commands.js 时,它又坏了。我尝试将它导入的路径从../commands 更改为./../commands、../commands.js、./../commands.js;没有工作。我将commands.js 移动到cmds/,仍然破产。我在两个cmds/ 中都尝试了console.log(Command),但他们都返回了undefined。
所有这一切都让它看起来像是一个导入问题,但我无法弄清楚这对我的生活有什么影响。请帮忙。
【问题讨论】:
-
我在尝试通过终端运行 sfdx 命令时遇到了同样的错误。 SFDX:创建项目甚至不起作用。我已经重新安装了我能做的所有事情; Npm LTS、Node、vscode 和软件包以及独立安装,似乎没有什么能解决我的问题。不知道是否与消息有关,但只是想我会发表评论。
标签: javascript node.js