#Geo: running in a client component errors out

4 messages · Page 1 of 1 (latest)

cold vine
#

If I import and attempt to use Geo from @aws-amplify/geo in my Next.js 14.1 project, I get errors about smithy and other underlying credentials providers trying to import 'fs'.

The client side is using unauth permissions and I've confirmed that the session is available. I've also confirmed that the configuration for geo in the Amplify config has been loaded.

component:

'use client';

import { Geo } from '@aws-amplify/geo';
import { useEffect } from 'react';

export default function GeoInput() {
    useEffect(() => {
        (async () => {
            const geoResults = await Geo.searchForSuggestions('Someplace, USA');
            console.log('geoResults', geoResults);
        })();
    }, []);

    return (
        <div>
            <input type="text" placeholder="Search for a location" />
        </div>
    );
}

in my gen2 amplify_outputs.json, here is the geo section:

  "geo": {
    "aws_region": "us-east-1",
    "search_indices": {
      "default": "dev-qasd0lkl-placeindex",
      "items": [
        "dev-qasd0lkl-placeindex"
      ]
    }
  }

here is the error i see:

./node_modules/@smithy/node-config-provider/node_modules/@smithy/shared-ini-file-loader/dist-es/slurpFile.js:1:0
Module not found: Can't resolve 'fs'
> 1 | import { promises as fsPromises } from "fs";
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2 | const { readFile } = fsPromises;
  3 | const filePromisesHash = {};
  4 | export const slurpFile = (path, options) => {

https://nextjs.org/docs/messages/module-not-found
cold vine
#

My updated theory after going down the dependency rabbit hole is that platform detection inside @aws-amplify/core is failing and it's not configured correctly for browser mode, so it's trying to do some SSR stuff in the client component.

cold vine
#

hmm or maybe it's just importing LocationClient at all

cold vine
#

okay nevermind it's Next.js' fault. --turbo doesn't work with the older @aws-amplify/core libraries imported by geo. --turbo does work with the latest aws-amplify libs, but until geo is refreshed to remove the older amplify dep tree, then it won't work with --turbo