i18next / i18next-browser-languageDetector

language detector used in browser environment for i18next
MIT License
873 stars 90 forks source link

Can't import i18next-browser-language-detector in SvelteKit (vite) using adapter-static #269

Closed codenius closed 2 years ago

codenius commented 2 years ago

🐛 Bug Report

In my SvelteKit (using vite) project with adapter-static configured, I cannot build static files, because I get an error when importing i18next-browser-language-detector.

(node:4019) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/project/node_modules/i18next-browser-languagedetector/dist/esm/i18nextBrowserLanguageDetector.js:1
import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1055:15)
    at Module._compile (node:internal/modules/cjs/loader:1090:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:533:24)
[vite-plugin-svelte-kit] Prerendering failed with code 1
error during build:
Error: Prerendering failed with code 1
    at ChildProcess.<anonymous> (file:///project/node_modules/@sveltejs/kit/src/exports/vite/index.js:442:15)
    at ChildProcess.emit (node:events:513:28)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)

To Reproduce

  1. create sveltekit project with npm create svelte (with typescript enabled)
  2. install adapter-static and configure in svelte.config.*
  3. install i18next-browser-language-detector and import anywhere with import LanguageDetector from 'i18next-browser-language-detector'
  4. run npm run build to build static files

Expected behavior

No errors and success when running npm run build

Your Environment

adrai commented 2 years ago

Can you try with v7.0.1?