Giter Site home page Giter Site logo

Comments (4)

joeyguerra avatar joeyguerra commented on April 27, 2024 3

I agree with Wes.

I'll add this to give you some suggestion though.

import { Router as viewRouter } from 'express'
viewRouter().get('/', (req, res) => {
  res.render('index')
})
export default viewRouter

Router is a function.

I would suggest the following instead for viewRouter.js

export default app => {
  app.get('/', (req, res) => {
    res.render('index')
  })
}

and in sicapp.js,

import express from 'express'
import viewRouter from './routes/viewRouter.js'
// other code
...

const app = express()
....
viewRouter(app)

from express.

cainbryce208 avatar cainbryce208 commented on April 27, 2024 2

Thank you both, I appreciate the feedback :D
Wes, not a problem. I'm not sure there is any particular use in supporting bun anyways as they either have wrappers or have their own implementation of node libraries. I think what it was though is the file encoding got messed up and maybe lost it from there? My suspicion is a formatter in VsCode.

Joey, this is an excellent alternative to what I was trying to do and even cleaner at that. I will have to take a gander at this when I'm in front of my editor again. Much appreciated.

from express.

wesleytodd avatar wesleytodd commented on April 27, 2024 1

I am nearly positive even if you get this issue worked out you will just hit other issues. Express couples deeply to Node.js api's which are likely different enough to matter. Just don't want to provide an answer on the errors without pointing out you are likely in for a world of pain 🤣. Additionally I don't think it has been discussed yet, but we likely do not have any plans to support Bun, so YMMV on this effort even in the longer term.

That said, it looks to me like something else is up with your code as I am not sure how the runtime difference could cause a typeof check to fail. And since that is the case, I am going to close this since we do not do technical support in here. If you can prove this is a bug of some sort in express please re-open this, but otherwise I would ask on Reddit or StackOverflow.

from express.

cainbryce208 avatar cainbryce208 commented on April 27, 2024

One thing I made an oopsie here with is the module.exports= viewRouter line which is commonJS .
Change it to default export viewRouter and I get the following error:

TypeError: argument handler must be a function
      at /mnt/z/sic-web/src/node_modules/router/lib/route.js:211:15
      at /mnt/z/sic-web/src/node_modules/express/lib/application.js:474:5
      at /mnt/z/sic-web/src/sicapp.js:11:1
206 | 
207 |     for (var i = 0; i < callbacks.length; i++) {
208 |       var fn = callbacks[i]
209 | 
210 |       if (typeof fn !== 'function') {
211 |         throw new TypeError('argument handler must be a function')
                    ^
TypeError: argument handler must be a function
      at /mnt/z/sic-web/src/node_modules/router/lib/route.js:211:15
      at /mnt/z/sic-web/src/node_modules/express/lib/application.js:474:5
      at /mnt/z/sic-web/src/sicapp.js:11:1
^C
cain@cain-pc:/mnt/z/sic-web/src$ bun run dev
$ bun --hot sicapp.js
206 | 
207 |     for (var i = 0; i < callbacks.length; i++) {
208 |       var fn = callbacks[i]
209 | 
210 |       if (typeof fn !== 'function') {
211 |         throw new TypeError('argument handler must be a function')
                    ^
TypeError: argument handler must be a function
      at /mnt/z/sic-web/src/node_modules/router/lib/route.js:211:15
      at /mnt/z/sic-web/src/node_modules/express/lib/application.js:474:5
      at /mnt/z/sic-web/src/sicapp.js:12:1
206 | 
207 |     for (var i = 0; i < callbacks.length; i++) {
208 |       var fn = callbacks[i]
209 | 
210 |       if (typeof fn !== 'function') {
211 |         throw new TypeError('argument handler must be a function')
                    ^
TypeError: argument handler must be a function
      at /mnt/z/sic-web/src/node_modules/router/lib/route.js:211:15
      at /mnt/z/sic-web/src/node_modules/express/lib/application.js:474:5
      at /mnt/z/sic-web/src/sicapp.js:12:1

from express.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.