【问题标题】:How Fix deploy nodejs in ubuntu如何修复在 ubuntu 中部署 nodejs
【发布时间】:2022-01-12 10:45:12
【问题描述】:

我有一个很奇怪的错误,不知道怎么解决。

我正在尝试将我的系统发布到 Ubuntu 18.04 服务器。

我安装了 NODEJS 和 NPM,服务器上的版本是: 节点 - v10.19.0 NPM - 6.14.4

我的后端在我的本地机器上工作正常,在我将它发布到 Ubuntu 的在线服务器上后,它开始出现此错误:

  init = ({ app } = {}) => {
       ^

SyntaxError: Unexpected token =
    at Object.compileFunction (vm.js:406:10)
    at Generator.next (<anonymous>)
    at Object.<anonymous> (/var/www/backend.io/src/index.js:1)
    at Generator.next (<anonymous>)

我的文件已满:

const i18next = require("i18next");
const Backend = require("i18next-node-fs-backend");
const i18nextMiddleware = require("i18next-express-middleware");

class I18nManager {
  t;
  currentLang;
  init = ({ app } = {}) => {
    i18next
      .use(Backend)
      .use(i18nextMiddleware.LanguageDetector)
      .init({
        backend: {
          loadPath: "locales/{{lng}}/{{ns}}.json",
        },
        fallbackLng: "en",
        preload: ["en", "pt-br"],
      })
      .then((_t) => (this.t = _t));

    if (app) app.use(i18nextMiddleware.handle(i18next));
  };
}

const i18n = new I18nManager();

module.exports = {
  i18n,
  t: (...args) => i18n.t(...args),
  currentLang: () => i18next.language,
};

【问题讨论】:

  • 您确定本地和在线服务器的节点版本相同吗?
  • 本地机器是windows,我的nodejs: v14.15 and npm 6.14.8

标签: javascript node.js express backend


【解决方案1】:

syntax you are using 需要 Node.js 12。

Node.js 10 无论如何都不再受支持。升级。

【讨论】:

    猜你喜欢
    • 2019-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-06
    • 1970-01-01
    • 2013-12-09
    • 2012-07-15
    • 2020-05-07
    相关资源
    最近更新 更多