what3words / w3w-node-wrapper

Node wrapper for the What3Words API
https://docs.what3words.com/api/v3/
MIT License
45 stars 10 forks source link

Error getting Grid Section #39

Closed am263129 closed 2 years ago

am263129 commented 2 years ago
Grid catch TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
    at GridSectionClient.<anonymous> (fetch.ts:16:1)
    at step (error.ts:49:1)
    at Object.next (error.ts:49:1)
    at error.ts:49:1
    at new Promise (<anonymous>)
    at globalThis.webpackHotUpdatenft_city../node_modules/@what3words/api/dist/lib/transport/fetch.js.__awaiter (error.ts:49:1)
    at GridSectionClient.fetchTransport [as transport] (fetch.ts:8:1)
    at GridSectionClient.<anonymous> (abstract.ts:80:1)
    at step (index.ts:5:1)
    at Object.next (index.ts:5:1)

here is my code

import what3words, { GridSectionClient, GridSectionOptions } from '@what3words/api';

const API_KEY = 'IBC4C9WV';
    const client = GridSectionClient.init(API_KEY);
    const options = {
      boundingBox: {
        southwest: { lat: 52.208867, lng: 0.117540 },
        northeast: { lat: 52.207988, lng: 0.116126 }
      }
    };
    client.run(options)
      .then((res) => console.log('Grid Section', res)).catch((res) => console.log('Grid catch', res));

and if I change code like this,

const API_KEY = 'IBC4C9WV';
    const client = GridSectionClient.init(API_KEY);
    const options = {
        southwest: { lat: 52.208867, lng: 0.117540 },
        northeast: { lat: 52.207988, lng: 0.116126 }
    };
    client.run(options)
      .then((res) => console.log('Grid Section', res)).catch((res) => console.log('Grid catch', res));

the result is

Grid catch Error: No bounding box specified
    at GridSectionClient.<anonymous> (abstract.ts:50:1)
    at step (index.ts:5:1)
    at Object.next (index.ts:5:1)
    at fulfilled (index.ts:5:1)

how can I fix and get correct result?

this is my package.json

{
  "name": "nft-city",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.3.0-beta3",
    "@fortawesome/free-solid-svg-icons": "^6.0.0-beta3",
    "@fortawesome/react-fontawesome": "^0.1.16",
    "@testing-library/jest-dom": "^5.16.1",
    "@testing-library/react": "^12.1.2",
    "@testing-library/user-event": "^13.5.0",
    "@what3words/api": "^4.0.4",
    "axios": "^0.25.0",
    "isomorphic-unfetch": "^3.1.0",
    "mapbox-gl": "^2.6.1",
    "os": "^0.1.2",
    "react": "^17.0.2",
    "react-cookie": "^4.1.1",
    "react-dom": "^17.0.2",
    "react-expand-animated": "^1.0.2",
    "react-helmet": "^6.1.0",
    "react-map-gl": "^6.1.18",
    "react-map-gl-geocoder": "^2.2.0",
    "react-router-dom": "^6.2.1",
    "react-scripts": "5.0.0",
    "react-seekbar-component": "^1.0.0",
    "sass": "^1.48.0",
    "web-vitals": "^2.1.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts --max_old_space_size=4096 build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "autoprefixer": "^10.4.2",
    "postcss": "^8.4.5",
    "tailwindcss": "^3.0.15"
  }
}
c5haw commented 2 years ago

@King-Mufasa - We have published a fix for this issue, if you could add the latest @what3words/api@4.0.5 and you can remove isomorphic-unfetch and instead add cross-fetch this should resolve your issue.