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.

Cannot destructure property `components` of 'undefined' or 'null'.

See original GitHub issue

I completed my project by using next-i18next. The project is working fine on local server. After I deployed the project to the server, firebase function console is giving me this error.

TypeError: Cannot destructure property components of 'undefined' or 'null'. at Server.renderToHTMLWithComponents (/srv/node_modules/next/dist/next-server/server/next-server.js:560:37) at Server.renderErrorToHTML (/srv/node_modules/next/dist/next-server/server/next-server.js:821:35) at <anonymous>

If I remove the codeline “appwithtranslation” from _app.js the page is loading without translation on the server.

import React from 'react'
import App from 'next/app'      
import { appWithTranslation } from '../i18n'

class MyApp extends App {
  render() {
      const { Component, pageProps } = this.props
      console.log("_appp",this.props)
    return ( 
        <Component {...pageProps} />
    )
  }
}

export default appWithTranslation(MyApp)

i18n.js

const NextI18Next = require('next-i18next').default

module.exports = new NextI18Next({
  defaultLanguage: 'en',
  otherLanguages: ['tr',"ar","ru"],
  localeSubpaths: {
    ar: "ar",
    en: 'en',
    tr: 'tr',
    ru:"ru"
  }
})

server.js


`const express = require('express')
const next = require('next')
const nextI18NextMiddleware = require('next-i18next/middleware').default

const nextI18next = require('./i18n')

const port = process.env.PORT || 3000
const app = next({ dev: process.env.NODE_ENV !== 'production' })
const handle = app.getRequestHandler();

(async () => {
  await app.prepare()
  const server = express()

  await nextI18next.initPromise
  server.use(nextI18NextMiddleware(nextI18next))

  server.get('*', (req, res) => handle(req, res))

  await server.listen(port)
  console.log(`> Ready on http://localhost:${port}`) // eslint-disable-line no-console
})()` 

Is there any solution that I can fix this problem?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Exilzcommented, Nov 2, 2020

Hey @Exilz, a quick question: what was the path of the public folder in your Dockerfile relative to the .next build?

Hi, in my case I just had to add this

COPY --from=builder /app/public/ ./public

2reactions
aquisebcommented, Jun 15, 2020

It seems to occur only when defaultLanguage does not have a matching locale dir with its common.json inside it. The error seems to only occur in production.

So let’s say defaultLanguage is set to de, the error is thrown when you forget to create public/static/locales/de/common.json.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot destructure property `components` of 'undefined' or 'null'.
The project is working fine on local server. After I deployed the project to the server, firebase function console is giving me this...
Read more >
Cannot destructure property of null - Stack Overflow
When the component tries to mount, it throws an error that it can't destructure user from auth because auth is null at that...
Read more >
Cannot destructure Property of Null Error in JavaScript
The "Cannot destructure property of null" error occurs when we try to destructure a property from a value that is equal to null...
Read more >
Next.js error: Cannot destructure property? : r/learnjavascript
I have tried removing the brackets which then leads to an error telling me that loginUser is undefined.
Read more >
[Solved]-Vuejs Cannot destructure property-Vue.js
Because you're destructing the second parameter which is undefined, remove the _ which is defined as first parameter: async signUp({ username, password, ...
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