【问题标题】:NextJS + Apollo + i18n - unexpected errorNextJS + Apollo + i18n - 意外错误
【发布时间】:2018-06-19 17:44:01
【问题描述】:

目前与我合作的客户要求我构建一个包含 i18n 的 SSR React 应用程序。为了解决这个问题,我尝试使用 NextJS 和 i18Next。

我设法让 react 和 apollo 毫无问题地连接起来,但是当我尝试连接 next + i18n 时,我不断收到一个非常无用的“意外错误”,错误。

检查控制台我还看到以下内容:

Cannot read property 'prototype' of undefined
TypeError: Cannot read property 'prototype' of undefined
    at Object.inherits (http://localhost:3000/_next/1515592576452/page/index.js:36080:46)
    at Object.<anonymous> (http://localhost:3000/_next/1515592576452/page/index.js:30216:6)
    at Object.<anonymous> (http://localhost:3000/_next/1515592576452/page/index.js:30440:30)
    at __webpack_require__ (http://localhost:3000/_next/1515592576452/manifest.js:714:31)
    at fn (http://localhost:3000/_next/1515592576452/manifest.js:117:20)
    at Object.<anonymous> (http://localhost:3000/_next/1515592576452/page/index.js:28246:12)
    at Object.module.exports.exports.byteLength (http://localhost:3000/_next/1515592576452/page/index.js:28507:30)
    at __webpack_require__ (http://localhost:3000/_next/1515592576452/manifest.js:714:31)
    at fn (http://localhost:3000/_next/1515592576452/manifest.js:117:20)
    at Object.<anonymous> (http://localhost:3000/_next/1515592576452/page/index.js:24501:18)

还有这个警告,但我不确定它是否相关

warning.js?e7f4ca8:33 Warning: Expected server HTML to contain a matching <div> in <div>.

我还注意到在 ./libs/withData.js 中有以下行:

enter code herestatic displayName = WithData(${getComponentDisplayName( ComposedComponent )})

我的编辑器将其标记为无效令牌,但此代码来自 nextjs example,并且该 repo 上没有问题,这表明这是一个错字。

我已在以下 codepen 项目中包含与此问题相关的所有代码。

https://codepen.io/foxleigh81/project/editor/DnYJWB

【问题讨论】:

    标签: javascript next.js apollo react-i18next


    【解决方案1】:

    好的,我已经解决了。

    简而言之。我在想这一切都错了。我在想我是在我的 react 应用程序旁边添加的,而现实更像是我将我的 react 应用程序放在里面。我把它拆开并从头开始重建,在nextjs repo 上组装示例,一切正常。

    【讨论】:

    • 你是如何解决withData.js中的unexpected token =的?
    • 技术上我没有。我将整个应用程序拆开并使用 repo 中的示例对其进行了重建,它工作正常。现在 NextJS 5 已经发布了,尽管我敢打赌还有更简单的方法。
    猜你喜欢
    • 1970-01-01
    • 2017-09-24
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-09
    • 2018-06-05
    • 2021-02-28
    相关资源
    最近更新 更多