Cannot find package 'typesafe-i18n' (sveletekit/vite/nodejs) #683
Answered
by
benjamin-brady
benjamin-brady
asked this question in
Q&A
-
I'm using sveltekit and node running on docker. Unless I copy the large
I have Dockerfile: # Stage 1 - Build
FROM node:18 AS build-env
COPY . /
WORKDIR /
RUN rm -rf node_modules && rm -rf build
RUN curl -sL https://unpkg.com/@pnpm/self-installer | node
RUN pnpm install
RUN pnpm run build
CMD ["node", "build/index.js"]
# # Stage 2 - Server
# FROM gcr.io/distroless/nodejs:18
# FROM gcr.io/distroless/nodejs18-debian11
FROM node:18-alpine as runner
ENV NODE_OPTIONS=--max_old_space_size=512
ENV NODE_ENV=production
WORKDIR /app
COPY --from=build-env /build ./
COPY --from=build-env /package.json ./
# ERROR UNLESS mode_modules is copied
COPY --from=build-env /node_modules ./node_modules
EXPOSE 80
EXPOSE 3000
CMD ["node","./index.js"] hooks.server.ts: import type { Locales } from '$i18n/i18n-types';
import { detectLocale, i18n, isLocale } from '$i18n/i18n-util';
import { loadAllLocales } from '$i18n/i18n-util.sync';
import type { Handle, RequestEvent } from '@sveltejs/kit';
import { initAcceptLanguageHeaderDetector } from 'typesafe-i18n/detectors';
import { env } from '$env/dynamic/private';
loadAllLocales();
const L = i18n();
export const handle: Handle = async ({ event, resolve }) => {
// ==== INTERNATIONALIZATION ====
// read language slug
const [, lang] = event.url.pathname.split('/');
// if slug is not a locale, use base locale (e.g. api endpoints)
const locale = isLocale(lang) ? (lang as Locales) : getPreferredLocale(event);
const LL = L[locale];
// bind locale and translation functions to current request
event.locals.locale = locale;
event.locals.LL = LL;
// ...
// replace html lang attribute with correct language
return resolve(event, { transformPageChunk: ({ html }) => html.replace('%lang%', locale) });
};
const getPreferredLocale = ({ request }: RequestEvent) => {
// detect the preferred language the user has configured in his browser
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language
const acceptLanguageDetector = initAcceptLanguageHeaderDetector(request);
return detectLocale(acceptLanguageDetector);
}; |
Beta Was this translation helpful? Give feedback.
Answered by
benjamin-brady
Jul 2, 2023
Replies: 1 comment 2 replies
-
Try to install it as a |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That didn't work but I think it's actually a vite issue not an issue with this library.