googlemaps / google-maps-services-js

Node.js client library for Google Maps API Web Services
Apache License 2.0
2.86k stars 631 forks source link

Error: Type '"origin" | undefined' is not assignable to type '"origin"' during Build. #1202

Open us24man opened 1 month ago

us24man commented 1 month ago

While building my Next JS project using "npm run build" I get this error.

Type error: Type '"origin" | undefined' is not assignable to type '"origin"'.
  Type 'undefined' is not assignable to type '"origin"'.
./node_modules/@googlemaps/js-api-loader/src/index.ts:301:5

  299 |   }: LoaderOptions) {
  300 |     this.apiKey = apiKey;
> 301 |     this.authReferrerPolicy = authReferrerPolicy;
      |     ^
  302 |     this.channel = channel;
  303 |     this.client = client;
  304 |     this.id = id || DEFAULT_ID; // Do not allow empty string

This is really annoying as i am unable to deploy the app to Vercel because of this.

Steps to reproduce: 1) Create a Next JS app 2) Install the latest version of this package 3) Build

package version 3.4.0 Next JS version 14.2.3 Typescript version ^5

wangela commented 1 month ago

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

@us24man 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.

us24man commented 1 month ago

I am unable to deploy my project to vercel due to this. Not sure if others are facing the same issue but this is pretty important for me.

majovkovic commented 1 month ago

@us24man Hello, I tried to reproduce your problem with same setup and everything works fine, I can build application.

"@googlemaps/google-maps-services-js": "^3.4.0",
"next": "14.2.3",
"typescript": "^5"

What version of Node you're using?

us24man commented 1 month ago

@majovkovic thank you for responding here. My node version is 20.11.1

majovkovic commented 1 month ago

@us24man Okay I dont think its about Node version. I'am passing build with 20.11.1. I would try to set "this.authReferrerPolicy" to: this.authReferrerPolicy = authReferrerPolicy || "origin"; or this.authReferrerPolicy = "origin";

us24man commented 1 month ago

@us24man Okay I dont think its about Node version. I'am passing build with 20.11.1. I would try to set "this.authReferrerPolicy" to: this.authReferrerPolicy = authReferrerPolicy || "origin"; or this.authReferrerPolicy = "origin";

I could go into node_modules and modify this to build locally but the issue will persist on Vercel. But the fact that you could build your Next JS app with this package installed means I might have some other package conflicting with it and causing issues in Build.

majovkovic commented 1 month ago

Most likely something else causes a problem. Anyway, good luck with your project.