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

HTMLDivElement is not defined #134

Open
FrancisBaah opened this issue Nov 4, 2023 · 8 comments
Open

HTMLDivElement is not defined #134

FrancisBaah opened this issue Nov 4, 2023 · 8 comments
Labels
type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@FrancisBaah
Copy link

FrancisBaah commented Nov 4, 2023

import { APILoader } from '@googlemaps/extended-component-library/react';

The code works fine on localhost, but give "HTMLDivElement is not defined" error on deploy.

@FrancisBaah FrancisBaah added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Nov 4, 2023
@wangela
Copy link
Member

wangela commented Nov 4, 2023

If you would like to upvote the priority of this issue, please comment below or react on the original post above with 👍 so we can see what is popular when we triage.

@FrancisBaah Thank you for opening this issue. 🙏
Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

@leafsy
Copy link

leafsy commented Nov 7, 2023

@FrancisBaah Could you provide more info/steps on how you are deploying the app, e.g. are you using one of the approaches described here? This will help us reproduce the issue. Thanks!

@awmack awmack removed the triage me I really want to be triaged. label Nov 8, 2023
@codeclown
Copy link

Error occurs in Next.js (Pages router) during server-side rendering:

 ⨯ ReferenceError: HTMLDivElement is not defined
    at file:///.../node_modules/@googlemaps/extended-component-library/lib/overlay_layout/overlay_layout.js:182:31
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:336:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:429:15) {
  page: '/'
}

When importing any React-component, e.g.:

import { PlacePicker } from "@googlemaps/extended-component-library/react";

Originates from overlay_layout.js:182:

180: __decorate([
181:     query('.main-container'),
182:     __metadata("design:type", HTMLDivElement)
183: ], OverlayLayout.prototype, "mainContainer", void 0);

Other similar lib/<component>/<component>.js files are probably susceptible to this too.

@ImperadorSid
Copy link

I'm having the same problem using Next.js

@leafsy
Copy link

leafsy commented Jul 8, 2024

Hi @codeclown @ImperadorSid, unfortunately Web Components in general don't work well with server-side rendering, though there're workarounds in the case of Next.js. Could you check if the dynamic loading technique used in this sample project helps? See docs for more info. Another option you may explore is @lit-labs/nextjs, but note that Lit SSR is under active development and has some limitations.

@jt6677
Copy link

jt6677 commented Aug 6, 2024

You need to do this

const DynamicCollegeFinderPage = dynamic( () => import('@/components/custom/map/CollegeFinderPage ').then((mod) => mod.CollegeFinderPage), { ssr: false, loading: () => <p>Loading...</p>, } )

@morgler
Copy link

morgler commented Aug 18, 2024

Dynamic loading doesn't seem to fully resolve the issue, because the error mentions overlay_layout.js, which isn't (or can't?) directly imported.

@HMubaireek
Copy link

Dynamic loading solves the issue for me in NextJs. A snippet:

'use client';
import React from 'react';
import dynamic from 'next/dynamic';
///.......
export const BaseMap = ({
  defaultValues,
  actions,
  mapOrigin,
  permits,
  children,
}: React.PropsWithChildren<Props>) => {
  const PlacePicker = dynamic(
    () =>
      import('@googlemaps/extended-component-library/react').then(
        (mod) => mod.PlacePicker,
      ),
    { ssr: false },
  );
  
///.......
};  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

9 participants