无法加载资源:服务器以404()的状态响应 - react部署可以找到文件,而i18翻译

发布于 2025-01-23 09:10:47 字数 1296 浏览 2 评论 0原文

我在部署投资组合时遇到麻烦。 我使用i18-reactnext库来翻译代码,并且在开发服务器中一切正常,但是当我进行构建时,我会遇到错误。 我尝试在vercel中部署Git Hub页面,即使在预览中,我也会遇到相同的错误。

我进入控制台的错误。

Failed to load resource: the server responded with a status of 404 
import React from 'react';
import ReactDOM from 'react-dom/client';
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import HttpApi from 'i18next-http-backend';

import App from './views/App';
import './reset.css';
import './index.css';
import 'bootstrap-icons/font/bootstrap-icons.css';
import 'flag-icon-css/css/flag-icons.min.css';

i18n
   .use(initReactI18next)
   .use(LanguageDetector)
   .use(HttpApi)
   .init({
      supportedLngs: ['pt', 'en'],
      fallbackLng: 'pt',
      detection: {
         order: ['cookie', 'localStorage', 'htmlTag', 'path', 'subdomain'],
         caches: ['cookie'],
      },
      backend: {
         loadPath: '../assets/locales/{{lng}}/translation.json',
      },
   });

ReactDOM.createRoot(document.getElementById('root')).render(
   <React.StrictMode>
      <App />
   </React.StrictMode>
);

I am having troubles deploying my portfolio.
I used the i18-reactnext library to translate the code and everything works fine in development server, but when i do the build i get the errors.
i tried deploying in git hub pages, in vercel and even in the preview i got the same errors.

Error i got in the console.

Failed to load resource: the server responded with a status of 404 
import React from 'react';
import ReactDOM from 'react-dom/client';
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import HttpApi from 'i18next-http-backend';

import App from './views/App';
import './reset.css';
import './index.css';
import 'bootstrap-icons/font/bootstrap-icons.css';
import 'flag-icon-css/css/flag-icons.min.css';

i18n
   .use(initReactI18next)
   .use(LanguageDetector)
   .use(HttpApi)
   .init({
      supportedLngs: ['pt', 'en'],
      fallbackLng: 'pt',
      detection: {
         order: ['cookie', 'localStorage', 'htmlTag', 'path', 'subdomain'],
         caches: ['cookie'],
      },
      backend: {
         loadPath: '../assets/locales/{{lng}}/translation.json',
      },
   });

ReactDOM.createRoot(document.getElementById('root')).render(
   <React.StrictMode>
      <App />
   </React.StrictMode>
);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文