Skip to content

Service worker issue #267

@bart-sofomo

Description

@bart-sofomo

Hello,
I'm using https://serwist.pages.dev/ for service worker where I have a code like this:

const firebaseApp = initializeApp({
  apiKey: env.NEXT_PUBLIC_FIREBASE_API_KEY,
  authDomain: env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
  projectId: env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
  storageBucket: env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
  messagingSenderId: env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
  appId: env.NEXT_PUBLIC_FIREBASE_APP_ID,
});

The problem is that it seems like bundling a service worker is a really specific case and somehow when I use env. instead of process.env the browser is claiming invalid variables for those that are used in server side. What I think is happening is service worker when importing env tries to access server side variables which are not available during build time (skipValidation: true on build).

Is there any way to fix this or should I simply not import env in service worker?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions