#Unable to upgrade using the Blitz 2.0 codemod, issues moving middleware to blitz server file

1 messages · Page 1 of 1 (latest)

reef jetty
#

✖ Move middleware to blitz server file
TypeError: Cannot read properties of undefined (reading 'name')
This is an unexpected error. Please ask for help in the discord #general-help channel. https://discord.blitzjs.com

#

that's the error I'm getting

#

i've found the related code in the codemod but I'm not sure what it's trying to do and I'm also not sure how to keep it from failing

#

import { sessionMiddleware, simpleRolesIsAuthorized } from "blitz"
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin

const hostnameMiddleware = (req, res, next) => {
res.blitzCtx.hostname = req.headers.host || env.CANONICAL_HOSTNAME || "workfrom.com"
next()
}

module.exports = {
reactStrictMode: true,
redirects() {
return [
{
source: "/admin",
destination: "/admin/cafes",
permanent: false,
},
{
source: "/signup",
destination: "/account/plans",
permanent: true,
},
]
},
middleware: [
sessionMiddleware({
cookiePrefix: "_workfrom_virtual-cafe",
isAuthorized: simpleRolesIsAuthorized,
}),
hostnameMiddleware,
],
webpack: (config, { isServer }) => {
if (!isServer) {
config.module = config.module || {}
config.module.rules = config.module.rules || []
const excluded = [/node_modules/twilio//]
excluded.forEach((excluded) => {
config.module.rules.push({ test: excluded, use: { loader: "null-loader" } })
})

  // bundle analyzer
  config.plugins = config.plugins || []
  config.plugins.push(new BundleAnalyzerPlugin({ analyzerMode: "disabled" /* 'server' */ }))

  // inline small images
  config.module.rules.push({
    test: /\.(png|jpg|gif)$/,
    type: "asset",
    parser: {
      dataUrlCondition: {
        maxSize: 5 * 1024, // 5kb
      },
    },
  })
}
return config

},
}

#

this is my blitz config

#

if the upgrade document could describe the steps being performed here maybe I could do them manually

#

Progress! I removed my custom middleware to capture the host in the session, and the codemod completed! The app still won't start tho

#

Okay I've gotten the app to start, but not it can't resolve the path to call the main server-side rpc call

#
Error while processing the request
Error: No resolver for path: /getInitialDashboardData
    at /home/zack/virtual-cafe/node_modules/@blitzjs/rpc/dist/index-server.cjs:211:15
    at Generator.next (<anonymous>)
    at fulfilled (/home/zack/virtual-cafe/node_modules/@blitzjs/rpc/dist/index-server.cjs:104:24)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)```
reef jetty
#

I've made progress, I am able to get some of the pages to load but for some reason a number of queries are failing to find the resolver, though not all of them! it's a conundrum

#

the failing queries are even listed in blitz routes so I'm not sure how to troubleshoot

#

I'm also getting an "unhandled error" popup on the page with Error: The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering. every single time, even when the page loads normally

#

nope, spoke too soon, i added "appDir: true" to my next config experimental section and now every page load fails again

#

progress! after a reinstall I am able to pull up working pages without error, now the only issues is the failure to route to my query resolvers

#
Error: No resolver for path: /getInitialDashboardData
    at /home/zack/virtual-cafe/node_modules/@blitzjs/rpc/dist/index-server.cjs:211:15
    at Generator.next (<anonymous>)
    at fulfilled (/home/zack/virtual-cafe/node_modules/@blitzjs/rpc/dist/index-server.cjs:104:24)```
#

i can't tell what the difference is between queries that route and ones that don't, but some just seem to work and others fail with the error above

#

some queries and pages work fine, but I can't figure out why some of them will not route

#

OH i see the codemod has removed blitz imports from all my files so half of them don't compile!

#

there is a bug in the codemod that removes valid imports from "blitz" package but leaves the calls to the imported names

#

like paginate and AuthorizationError

reef jetty
#

i am fixing hundreds of files that were broken by this codemod

#

not much good if it mangles working files

reef jetty
#

okay! I've cleaned up the code that was mangled by the codemod, and fixed up the spots that it missed, now I just have a random (?) selection of my endpoint routes failing to resolve

#

The routes are listed in npx blitz routes and I'm stuck! not sure how to troubleshoot this, some of my query routes are working and some are not

#

these obviously were working before the blitz 2.0 update

reef jetty
#

FOUND IT the offending routes had .tsx extensions

#

i'd argue that's a bug in blitz routes but we got there!

reef jetty
#

okay I am ready to declare victory here, thanks empty channel!

uneven surge
#

Hey @reef jetty happy you were able to get it working. But not happy you had such a hard time with the codemod.

Would you say the main issues were with the custom middleware & blitz imports?

reef jetty
#

I’d be happy to go into detail so we can improve it for those that come after. In my case the biggest preventable issue was probably the codemod removing valid imports from blitz that I had to reintroduce

#

ooh and a hint about the .tsx RPC endpoints, since those worked before, a warning would help for that too

#

overall this went very smoothly once I focused on it, and the codemod and guide were a big help

uneven surge