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

Xhr.js ReferenceError: $ is not defined #191

Open
StefanVrecic opened this issue Aug 4, 2021 · 7 comments
Open

Xhr.js ReferenceError: $ is not defined #191

StefanVrecic opened this issue Aug 4, 2021 · 7 comments

Comments

@StefanVrecic
Copy link

Newb here, do I just add " import * as $ from 'jquery' " into xhr.ts and then rebuild it using "npm run-script build-app" ?

That's what I tried but no luck, 'node_modules' not recognized as an internal or external command. Not sure how to configure the scripts or resolve this issue otherwise :/

(Have already taken a look at the other issues and your responses)
Thank you :)

@tikurahul
Copy link
Collaborator

Did you npm install after cloning the repository ?

@StefanVrecic
Copy link
Author

StefanVrecic commented Aug 5, 2021

Did you npm install after cloning the repository ?

Used npm i @openid/appauth from my project to install this as per usual

Tried npm install from the appauth's root folder with the package.json, same error with 'node_modules' not recognized

Using Windows.

@foxtree
Copy link

foxtree commented Aug 25, 2021

I just encountered this issue, and resolved it by installing jquery (npm or yarn), and:

import $ from 'jquery';

global.$ = $  // or: window.$ = $

The surprising thing here is that jquery is neither installed as a sub-dependency, nor specified as a peer dependency, and it's not imported/required by this library -- $ is assumed to just exist as a global.

(also: maybe jquery could be dispensed with, entirely, and replaced with a library that's more focused on data fetches. ...or perhaps just fetch)

@sidharthramesh
Copy link

You can just use it with the fetch API like so:

import {
    AuthorizationServiceConfiguration,
    FetchRequestor,
  } from "@openid/appauth";
await AuthorizationServiceConfiguration.fetchFromIssuer(
      openIdConnectUrl,
      new FetchRequestor()
    );

@tpluscode
Copy link

Thanks @sidharthramesh

Good grief, that should be the default!

@sidharthramesh
Copy link

Yes. I think this should be the default too

@TranquilMarmot
Copy link

TranquilMarmot commented May 31, 2024

This is the first time I've encountered jQuery in probably 8 years! What a bizarre default.

You can also set this for BaseTokenRequestHandler:

const tokenHandler = new BaseTokenRequestHandler(new FetchRequestor());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants
@TranquilMarmot @tpluscode @tikurahul @foxtree @sidharthramesh @StefanVrecic and others