i18next / i18next-http-backend

i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.
MIT License
453 stars 70 forks source link

TypeError: ActiveXObjectApi is not a constructor #72

Closed david238 closed 3 years ago

david238 commented 3 years ago

🐛 Bug Report

Error in console: TypeError: ActiveXObjectApi is not a constructor at requestWithXmlHttpRequest (/Users/david/werweev2-dev/node_modules/i18next-http-backend/cjs/request.js:105:11) at Object.request (/Users/david/werweev2-dev/node_modules/i18next-http-backend/cjs/request.js:159:12) at Backend.loadUrl (/Users/david/werweev2-dev/node_modules/i18next-http-backend/cjs/index.js:115:20) at Backend.read (/Users/david/werweev2-dev/node_modules/i18next-http-backend/cjs/index.js:108:12) at Connector.read (/Users/david/werweev2-dev/node_modules/i18next/dist/cjs/i18next.js:1669:34) at Connector.loadOne (/Users/david/werweev2-dev/node_modules/i18next/dist/cjs/i18next.js:1727:12) at /Users/david/werweev2-dev/node_modules/i18next/dist/cjs/i18next.js:1703:16 at Array.forEach () at Connector.prepareLoading (/Users/david/werweev2-dev/node_modules/i18next/dist/cjs/i18next.js:1702:21) at Connector.load (/Users/david/werweev2-dev/node_modules/i18next/dist/cjs/i18next.js:1709:12) at I18n.loadResources (/Users/david/werweev2-dev/node_modules/i18next/dist/cjs/i18next.js:2071:40) at setLng (/Users/david/werweev2-dev/node_modules/i18next/dist/cjs/i18next.js:2167:16) at I18n.changeLanguage (/Users/david/werweev2-dev/node_modules/i18next/dist/cjs/i18next.js:2177:9) at Timeout.load [as _onTimeout] (/Users/david/werweev2-dev/node_modules/i18next/dist/cjs/i18next.js:2021:16) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7)

To Reproduce

I have an i18n.js file that is as follows:

import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import LanguageDetector from 'i18next-browser-languagedetector';
import HttpApi from 'i18next-http-backend';

i18n
  // .use(LanguageDetector)
  .use(initReactI18next) // passes i18n down to react-i18next
  .use(HttpApi)
  .init({
    fallbackLng: "en",
    keySeparator: false, // we do not use keys in form messages.welcome
    interpolation: {
      escapeValue: false // react already safes from xss
    },
    detection: {
        order: ['htmlTag', 'cookie', 'sessionStorage', 'localStorage', 'querystring', 'navigator', 'path', 'subdomain'],
        caches: ['cookie', 'localStorage']
    },
    backend: {
        loadPath: '/api/translation/{{lng}}'
    },
    react: {
        useSuspense: false
    },
    load: 'languageOnly'
  });

  export default i18n;

express.js ( I am doing server-rendering) as follows:

app.get('*', (req, res) => {
  const sheets = new ServerStyleSheets()
  const context = {}
  const store = createStore(rootReducer);
  console.log('req.url', req.url);
  const markup = ReactDOMServer.renderToString(
    sheets.collect(
        <Provider store={store}>
            <StaticRouter location={req.url} context={context}>
              <ThemeProvider theme={theme}>
                <MainRouter />
              </ThemeProvider>
            </StaticRouter>
        </Provider>
    )
  );
  const helmet = Helmet.renderStatic();
  // console.log('helmet', helmet);
  if (context.url) {
    return res.redirect(303, context.url)
  }

  const css = sheets.toString();
  res.status(200).send(Template({
    markup: markup,
    css: css,
    helmet: helmet
  }));
})

not sure if that is related to the error.

Expected behavior

Do you know how can I get rid of this typeError message in the console?

Your Environment

Version tried: "i18next-http-backend": "^1.2.1", & "i18next-http-backend": "^1.2.6". "i18next": "^20.2.1", "i18next-browser-languagedetector": "^6.1.0", "i18next-http-backend": "^1.2.6",

adrai commented 3 years ago

Ca you please create a reproducible example? Maybe a repo I can clone and test?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

david238 commented 3 years ago

Hi I Sorry for the late reply, I have isolated the issue, it seems to have a conflicting issue with another npm package called 'recordrtc'.

By commenting and uncommenting this line, the error message does not show.

import RecordRTC from 'recordrtc';

RecordRTC package: https://www.npmjs.com/package/recordrtc

Not sure if that would help out? I will try to create a new project and replicate the issue in the next days. Sorry about that, been taken up a bit these days.

Thank you David

adrai commented 3 years ago

sorry, i have no idea

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

eakarpov commented 2 years ago

This is also actual for me - I get the same error.

eakarpov commented 2 years ago

TypeError: ActiveXObjectApi is not a constructor [1] at requestWithXmlHttpRequest (/Users/georgecarpow/Documents/znamenica/allslavic-front/allslavic/node_modules/i18next-http-backend/esm/request.js:92:1) [1] at Object.request (/Users/georgecarpow/Documents/znamenica/allslavic-front/build/webpack:/allslavic/node_modules/i18next-http-backend/esm/request.js:146:1) [1] at Backend.loadUrl (/Users/georgecarpow/Documents/znamenica/allslavic-front/build/webpack:/allslavic/node_modules/i18next-http-backend/esm/index.js:108:1) [1] at /Users/georgecarpow/Documents/znamenica/allslavic-front/build/webpack:/allslavic/node_modules/i18next-http-backend/esm/index.js:100:1 [1] at runNextTicks (internal/process/task_queues.js:58:5) [1] at listOnTimeout (internal/timers.js:523:9) [1] at processTimers (internal/timers.js:497:7)

eakarpov commented 2 years ago

Problem exists on MacOS and Windows

adrai commented 2 years ago

a reproducible example would help

eakarpov commented 2 years ago

https://github.com/znamenica/allslavic-front/tree/0.1.1 - here is the example. Including package via import causes the error whenever the backend i18n loading option is using or not.

adrai commented 2 years ago

can you try with v1.4.1 ?

eakarpov commented 2 years ago

Yes, the error has gone, thanks.