question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting "TypeError: __getAllUserFiles is not a function" when running production server

See original GitHub issue

Hi there,

When I run yarn server:prod the server starts fine (I see the server running at http://localhost:3000 message) but, when I try to make a request from the browser I get an error message in the console and the browser never receives a response.

The dev server (yarn dev) does not have this problem.

I followed the “Manual Installation” section of the README for React + TypeScript so it’s possible I missed something but, as far as I can tell, what I have is the same as the react-typescript boilerplate.

Error message:

(node:27112) UnhandledPromiseRejectionWarning: TypeError: __getAllUserFiles is not a function
    at Object.getAllUserFiles (.../node_modules/vite-plugin-ssr/user-files/infra.node.ts:13:10)
    at Object.getUserFiles (.../node_modules/vite-plugin-ssr/user-files/getUserFiles.shared.ts:18:38)
    at Object.getPageIds (.../node_modules/vite-plugin-ssr/route.node.ts:166:21)
    at renderPage (.../node_modules/vite-plugin-ssr/renderPage.node.ts:48:22)
    at .../index.ts:25:20

package.json script:

"scripts": {
    // ...
    "server:prod": "cross-env NODE_ENV=production ts-node ./server",
},

server/index.ts:

import express from 'express'
import { createPageRender } from 'vite-plugin-ssr'
import * as vite from 'vite'

const isProduction = process.env.NODE_ENV === 'production'
const root = `${__dirname}/..`

async function startServer() {
  const app = express()

  let viteDevServer: vite.ViteDevServer | undefined

  if (isProduction) {
    app.use(express.static(`${root}/dist/client`, { index: false }))
  } else {
    viteDevServer = await vite.createServer({ root, server: { middlewareMode: true }})
    app.use(viteDevServer.middlewares)
  }

  const renderPage = createPageRender({ viteDevServer, isProduction, root })

  app.get('*', async (req, res, next) => {
    const url = req.originalUrl
    const contextProps = {}
    const result = await renderPage({ url, contextProps })
    if (result.nothingRendered) return next()
    res.status(result.statusCode).send(result.renderResult)
  })

  const port = 3000
  app.listen(port, () => {
    console.log(`🚀 server running at http://localhost:${port}`)
  })
}

startServer()

Any help would be appreciated. Thanks in advance.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
brilloutcommented, Mar 17, 2021

I can reproduce, let me fix this.

0reactions
stephensamracommented, Mar 17, 2021

Works perfectly - thanks so much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 11 production fails with error: ERROR TypeError
Recently in my company there was an upgrade of angular app version to 11. App locally compiles and runs without a problem with...
Read more >
"TypeError: Object(...) is not a function" with create-next-app ...
The problem is 100% reproducible on my machine with Next.js 10.0.7 (latest), 10.0.6, and 10.0.5. The problem is resolved by downgrading to 10.0....
Read more >
Getting TypeError: $A.run is not a function after Summer 16 ...
For that, I go to the Developer Console and look at the actual code that is on the server and verify that the...
Read more >
Uncaught TypeError | Is Not A Function | Solution - YouTube
Have you encountered an error like:- Uncaught TypeError - Some selector is not a function - jQuery is not a function - owlCarousel...
Read more >
How to fix "Uncaught TypeError: x is not a function" in JavaScript
JS Casts 01 - How to fix "Uncaught TypeError : x is not a function " in JavaScript.Visit https://javascriptcasts.com/episodes/01 for a summary ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found