opral / inlang-paraglide-js

Tree-shakable i18n library build on the inlang ecosystem.
https://inlang.com/m/gerre34r/library-inlang-paraglideJs
23 stars 0 forks source link

[NextJS 14.2.1] Warning from paraglide #102

Closed polvallverdu closed 2 months ago

polvallverdu commented 2 months ago

I'm receiving this warning every time the webpage refreshes:

 ⚠ ./node_modules/.pnpm/@inlang+paraglide-next@0.1.6_next@14.2.3_react@18.2.0/node_modules/@inlang/paraglide-next/dist/paraglide-next/src/app/navigation.js
Attempted import error: 'useRouter' is not exported from 'next/navigation' (imported as 'NextNavigation').

Import trace for requested module:
./node_modules/.pnpm/@inlang+paraglide-next@0.1.6_next@14.2.3_react@18.2.0/node_modules/@inlang/paraglide-next/dist/paraglide-next/src/app/navigation.js
./node_modules/.pnpm/@inlang+paraglide-next@0.1.6_next@14.2.3_react@18.2.0/node_modules/@inlang/paraglide-next/dist/paraglide-next/src/app/createI18n.server.js
./node_modules/.pnpm/@inlang+paraglide-next@0.1.6_next@14.2.3_react@18.2.0/node_modules/@inlang/paraglide-next/dist/app/index.server.js
./src/app/layout.tsx
./node_modules/.pnpm/next@14.2.3_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/build/webpack/loaders/next-app-loader.js?name=app%2Fpage&page=%2Fpage&appPaths=%2Fpage&pagePath=private-next-app-dir%2Fpage.tsx&appDir=D%3A%5Cvscode%5Credacted%5Csrc%5Capp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=D%3A%5Cvscode%5Credacted&isDev=true&tsconfigPath=tsconfig.json&basePath=&assetPrefix=&nextConfigOutput=&preferredRegion=&middlewareConfig=e30%3D!./src/app/page.tsx?__next_edge_ssr_entry__
LorisSigrist commented 2 months ago

Ah, I see what's happening
The navigation.ts file in Paraglide-Next is used both in server and client component contexts. If it's imported from the server component it doesn't use the next/navigation but the import statement is still there which triggers the warning.

The fix here is to split out the part that uses next/navigation into it's own file & have two files for server / client components.

polvallverdu commented 2 months ago

Thank you for the fast fix 😄 I know it was just a warning, but it got annoying really fast.