Intenté lanzar un chatbot que se hizo con botkit y javascript. Sin embargo obtenía un TypeError: require(...) is not a function
:
C:\Users\antoi\Documents\Programming\PACO\Code 19-04-03\app\components\express_webserver.js:22
require("./express_middleware/" + file)(webserver, controller);
^
TypeError: require(...) is not a function
at C:\Users\antoi\Documents\Programming\PACO\Code 19-04-03\app\components\express_webserver.js:22:46
at Array.forEach (<anonymous>)
at module.exports (C:\Users\antoi\Documents\Programming\PACO\Code 19-04-03\app\components\express_webserver.js:21:6)
at Object.<anonymous> (C:\Users\antoi\Documents\Programming\PACO\Code 19-04-03\app\bot.js:62:72)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
No sé si el error proviene de una dependencia circular. En cualquier caso, no puedo ser exportado a un módulo ./App/route
porque no hay ninguno.
express_webserver.js
var express = require("express");
var bodyParser = require("body-parser");
var querystring = require("querystring");
var debug = require("debug")("botkit:webserver");
module.exports = function(controller, bot) {
var webserver = express();
webserver.use(bodyParser.json());
webserver.use(bodyParser.urlencoded({ extended: true }));
webserver.use((req, res, next) => {
// res.setHeader('X-Frame-Options', 'ALLOW-FROM https://www.messenger.com/ https://www.facebook.com/');
// res.setHeader("X-Frame-Options", "ALLOW-FROM https://www.facebook.com/");
// res.setHeader('X-Frame-Options', 'ALLOW-FROM https://l.facebook.com/');
next();
});
// import express middlewares that are present in /components/express_middleware
var normalizedPath = require("path").join(__dirname, "express_middleware");
require("fs")
.readdirSync(normalizedPath)
.forEach(function(file) {
require("./express_middleware/" + file)(webserver, controller);
});
webserver.use(express.static("build"));
webserver.use(express.static('public'));
webserver.listen(process.env.PORT || 3000, null, function() {
debug(
"Express webserver configured and listening at http://localhost:" +
process.env.PORT || 3000
);
});
// import all the pre-defined routes that are present in /components/routes
var normalizedPath = require("path").join(__dirname, "routes");
require("fs")
.readdirSync(normalizedPath)
.forEach(function(file) {
require("./routes/" + file)(webserver, controller);
});
controller.webserver = webserver;
return webserver;
};