Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I cant generate because astro-i18next send error "Could not find a config file at "./"" in astro-i18next/dist/cli/index.js:352:2020 #203

Open
dopvCaerux opened this issue Feb 26, 2025 · 1 comment

Comments

@dopvCaerux
Copy link

dopvCaerux commented Feb 26, 2025

I already setup base on docs version "astro-i18next": "^1.0.0-beta.21", now i'm using node 22.12.0

astro.config.mjs

`import { defineConfig } from "astro/config";
// import preact from "@astrojs/preact";
import { VITE_CSS, VITE_PLUGINS } from "./config/vite";

import react from "@astrojs/react";
import astroI18next from "astro-i18next";

// https://astro.build/config
export default defineConfig({
integrations: [react(), astroI18next()],
site: "https://example.com",
vite: {
ssr: {},
plugins: VITE_PLUGINS,
css: VITE_CSS,
},
});

**astro-i18next.config:** /** @type {import('astro-i18next').AstroI18nextConfig} */
export default {
defaultLocale: "en",
locales: ["en", "vi"],
namespaces: ["common", "index"],
defaultNamespace: "common",
};
`
and i have public/local/en & public/local/vi

after setting I run command generate and receive error
`npx astro-i18next generate

file:///Users/tsu/Documents/caerux-ex/astro-test/node_modules/astro-i18next/dist/cli/index.js:352
+e,uE=(e,i=1)=>(e.startsWith("./")&&i>0&&(e=e.slice(2)),e.padStart(e.length+i*3,"../")),NW=e=>/((^_)|(\/_))/.test(e),RI=(e,i)=>(e=e.replace(/(import\s+.*["'])(\..*)(["'])/g,(l,_,h,p)=>${}${uE(h,i)}${p}),e=e.replace(/(Astro.glob\(["'])(\..*)(["']\))/g,(l,_,h,p)=>${}${uE(h,i)}${p}),e=e.replace(/(<script\s+src=["'])(\..*)(["'])/g,(l,_,h,p)=>${}${uE(h,i)}${p}),e),BI=e=>ey.default.createSourceFile("x.ts",AW(e),ey.default.ScriptTarget.Latest),JI=(e,i)=>{let l=ey.default.transform(e,[II],{locale:i});return ey.default.createPrinter().printNode(ey.default.EmitHint.Unspecified,l.transformed[0],e)},lE=(e,i=void 0,l=[])=>{let _=new wI.fdir().filter(h=>!NW(h)&&h.endsWith(".astro")).exclude(h=>l.includes(h)).withFullPaths();return i?_.crawl(${e}${FI.sep}${i}).sync():_.crawl(e).sync()},jI=e=>{e.forEach(i=>{OI.default.ensureDirSync(FI.dirname(i.path)),kW.writeFileSync(i.path,i.source)})},UI=(e,i=null,l="",_={})=>{if(e=e.replace(/^\/+|\/+$/g,""),l=l.replace(/\/+$/g,""),i===null)return${l}/${e};e=e.replace(/.astro$/,"");let h=/${i}/${e};return Object.prototype.hasOwnProperty.call(_,h)?${l}${[h]}.astro:${l}/${i}/${e}.astro};var zI=(e,i,l,_=!1,h,p=e)=>{let P=process.hrtime(),z=_?lE(e,i,l):lE(e,void 0,l),U=[];return z.forEach(async function(g){let v=E0(g).replace(E0(e),""),Y=_?[e,i,v].join("/"):[e,v].join("/"),Z=PW.readFileSync(Y).toString(),ie=BI(Z);l.forEach(te=>{let x=te!==i,J=_?0:Number(x),d=JI(ie,te),D=LI(Z,d);D=RI(D,J);let C=_?!0:x;U.push({path:E0(UI(v,C?te:void 0,p,h)),source:D})})}),jI(U),{filesToGenerate:U,timeToProcess:process.hrtime(P)[1]/1e6}};import{pathToFileURL as wW}from"url";import mG,{t as vG}from"i18next";import{fileURLToPath as WI}from"url";import VI from"@proload/core";import IW from"@proload/plugin-tsm";var qI=async(e,i)=>{let l=WI(e),_;if(i){let h=/^\.*\//.test(i)?i:./${i};_=WI(new URL(h,e))}return VI.use([IW]),await VI("astro-i18next",{mustExist:!1,cwd:l,filePath:_})};var HI=async e=>{let{path:i,config:l}=e,_=await qI(wW(i),l);if(i&&!(_!=null&&_.value))throw new Error(Could not find a config file at ${JSON.stringify(i)}. Does the file exist?);return{...e,config:_==null?void 0:_.value}},GI=async e=>{let{path:i}=e;return{...e,path:i.endsWith("/")?i:i+"/"}};JN(rC(process.argv)).usage("usage: $0 <command>").command("generate [path] [options]","generates localized Astro pages",e=>e.positional("path",{type:"string",description:"Path to the Astro project folder",default:"./"}).option("output",{alias:"o",type:"string",description:"Set the output of the generated pages if different from input"}),async e=>{e.verbose&&console.info(Generating localized pages: ${e.config.locales});let i=e.path+"src/pages",l=Hx(e.config.routes),_=zI(i,e.config.defaultLocale,e.config.locales,e.config.showDefaultLocale,l,e.output);if(e.verbose){let h=_.filesToGenerate.map(p=>p.path);console.log(

Error: Could not find a config file at "./". Does the file exist?
at HI (file:///Users/tsu/Documents/caerux-ex/astro-test/node_modules/astro-i18next/dist/cli/index.js:352:2020)
at async Promise.all (index 1)`

does anyone explain and help me fix this?
thank you

@dopvCaerux
Copy link
Author

I tried with node 20, this working now. maybe this only appear in node 22 now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant