-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: expressify is not a function #29
Comments
This works fine - could not reproduce it here. Please provide a complete example (including |
thank you replay server.js: const uwsApp = uWS.App().ws('/', {
}) const app = expressify(uwsApp) package.json: { Do: |
Using npm's uWebSockets-express 1.3.4, node v18.9.0 While trying to set up uWS with express, I ran into this issue as well. To fix this, I tried checking what the default export was doing using console.log debugging. import expressify from 'uwebsockets-express';
console.log(expressify);
/* Prints
{
Application: [Getter],
IncomingMessage: [Getter],
ServerResponse: [Getter],
Socket: [Getter],
default: [Function: default_1]
}
*/ Looking into the index.js files, this expressify.default did seem to be the function that accepted a uWS.App and returned an express Application, so I aliased import uWSExpress from "uwebsockets-express"
const expressify = uWSExpress.default;
console.log(expressify);
/* Prints
[Function: default_1]
*/ This seems to be the real import { fileURLToPath } from 'url';
import path, { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename); // dealing with "type":"module"
import express from 'express';
import uWS from "uWebSockets.js"
import expressify from "uwebsockets-express"
const uwsApp = uWS.App();
const app = expressify.default(uwsApp); // or alias it, either works (.default was added)
// use existing middleware implementations!
app.use(express.json());
// app.use('/', serveIndex(path.join(__dirname, ".."), { icons: true, hidden: true })) // not sure which serveIndex this is from
app.use('/', express.static(path.join(__dirname, "..")));
// register routes
app.get("/hello", (req, res) => {
res.json({ hello: "world!" });
});
app.listen(8000); You can test this by going to I'm confused why this works, and according to this project's |
Using the example you provided, ok thank you |
+1 on this, having to do the |
example:
import uWS from "uWebSockets.js"
import expressify from "uwebsockets-express"
const uwsApp = uWS.App();
const app = expressify(uwsApp);
// use existing middleware implementations!
app.use(express.json());
app.use('/', serveIndex(path.join(__dirname, ".."), { icons: true, hidden: true }))
app.use('/', express.static(path.join(__dirname, "..")));
// register routes
app.get("/hello", (req, res) => {
res.json({ hello: "world!" });
});
app.listen(8000);
Error:
const app = expressify(uwsApp)
^
TypeError: expressify is not a function
Operation process:
1.npm i uWebSockets.js-express
2.npm i uNetworking/uWebSockets.js#v20.31.0
3. npm i express
4. npm i -D [email protected]
The text was updated successfully, but these errors were encountered: