如何在执行node-wit和wit.ai文档提供的代码时解决来自Node.js的“Wit不是构造函数”错误。
html,
body {
font-family: Helvetica, Arial, Sans-Serif;
padding: 0px;
margin: 0px;
}
.parent {
width: 100%;
min-height: 25vh;
max-height: auto;
position: relative;
/* so center-area can be positioned absolute */
display: inline-block;
background: transparent;
}
center-area {
/* let it fill the whole container */
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: inline-block;
}
.center-area:before {
content: '';
display: inline-block;
vertical-align: middle;
height: 100%;
}
.centered {
display: inline-block;
vertical-align: middle;
font-size: 18px;
background: green;
z-Index: 1;
border: 50px solid lightblue;
}
.clear_both {
clear: both;
}
我通过升级和降级npm / node版本尝试了所有方法,但没有运气。
更新:请找到我使用的index.js来源,
我是否需要更改此内容?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
<div class="parent">
<div class="center-area">
<!--
-->
<div class="centered">
<p>
<button class="addContent">add content</button><strong>This content is vertically centered inside this div... </strong>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam consequat quam bibendum nibh cursus viverra. Duis suscipit bibendum faucibus. Praesent sit
amet lectus sapien, ut dignissim augue.</p>
<div style="clear: both"></div>
</div>
</div>
</div>
答案 0 :(得分:0)
您的问题有两个典型原因,要么忘记require
您的模块,要么忘记npm install
它。检查你是否:
require('node-wit')
并从返回的对象中获取构造函数:
const Wit = require('node-wit').Wit
Wit
,但忘记了npm install node-wit
答案 1 :(得分:0)
对于使用messenger.js作为index.js的每个人都使用:
const Wit = require('./lib/wit');
const log = require('./lib/log');
答案 2 :(得分:0)
请检查node_modules目录中的node-wit包。
如果存在node-wit,请在尝试创建其实例之前请求它。
const {Wit} = require('node-wit');
witHandler = new Wit({
accessToken: accessToken
});