Giter VIP home page Giter VIP logo

Comments (10)

jeremyrajan avatar jeremyrajan commented on June 11, 2024 3

Yeap solved it using,

global.XMLHttpRequest = require("xhr2");

You can do this in your _app.ts if you are using nextjs@12 or in layout.tsx if you are using nextjs@13

from mapbox-gl-directions.

thomastkt avatar thomastkt commented on June 11, 2024

Hi, I have the same issue with angular, I tried what you did with xhr2 dependency but it doesn't work for me.
If anyone has a solution, that would be great

from mapbox-gl-directions.

heyimcarlos avatar heyimcarlos commented on June 11, 2024

@spencerjsmall could you show some code on how you fixed this? Using Nextjs and having the exact same issue.

from mapbox-gl-directions.

spencerjsmall avatar spencerjsmall commented on June 11, 2024

@renzik At the top of dist/mapbox-gl-directions.js I included var xhr = require('xhr2'), then replaced the three or so XMLHttpRequests with xhr. This didn't work when I set the xhr2 constructor name to XMLHttpRequest and I also needed to add a blank line after the xhr2 import statement. Hope this helps.

from mapbox-gl-directions.

ljq2022 avatar ljq2022 commented on June 11, 2024

Bumping this thread if anyone has found alternative fixes to the issue.

from mapbox-gl-directions.

arnevankauter avatar arnevankauter commented on June 11, 2024

Any ideas to fix this issue?

from mapbox-gl-directions.

minjaekwon9 avatar minjaekwon9 commented on June 11, 2024

When I tried the fix it gives me the error:

Class constructor XMLHttpRequest cannot be invoked without 'new'

from mapbox-gl-directions.

jmndao avatar jmndao commented on June 11, 2024

Hello, thanks @jeremyrajan . Your solution works form me.
However, I should mention these steps to make it more clear (for my case):

  • install xhr2 pkg using yarn or npm yarn add xhr2
  • import it `import xhr2 from "xhr2"
  • Then, use the line @jeremyrajan indicates to fix it global.XMLHttpRequest = xhr2

Thanks

from mapbox-gl-directions.

qbacuber avatar qbacuber commented on June 11, 2024

Hey i have a similar problem in my nextjs application.
I've switched from page to app route and I'm having a problem with just authorization using next-auth and grpc.
I added this code snippet in layout.tsx and still get error.

global.XMLHttpRequest = require("xhr2");

error:

..\node_modules\grpc-web\index.js (18:499) @ self
app:dev: - error Error [ReferenceError]: self is not defined

stack:
next: 13.4.7
next-auth: 4.22.1
react: 18.2.0
xhr2: 0.2.1

from mapbox-gl-directions.

GuyFawkesII avatar GuyFawkesII commented on June 11, 2024

Hey i have a similar problem in my nextjs application. I've switched from page to app route and I'm having a problem with just authorization using next-auth and grpc. I added this code snippet in layout.tsx and still get error.

global.XMLHttpRequest = require("xhr2");

error:

..\node_modules\grpc-web\index.js (18:499) @ self
app:dev: - error Error [ReferenceError]: self is not defined

stack: next: 13.4.7 next-auth: 4.22.1 react: 18.2.0 xhr2: 0.2.1

same problem , have you managed to fixed it yet?

from mapbox-gl-directions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.