openid / AppAuth-JS

JavaScript client SDK for communicating with OAuth 2.0 and OpenID Connect providers.
Apache License 2.0
972 stars 162 forks source link

Xhr.js ReferenceError: $ is not defined #191

Open StefanVrecic opened 2 years ago

StefanVrecic commented 2 years ago

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 commented 2 years ago

Did you npm install after cloning the repository ?

StefanVrecic commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

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

Thanks @sidharthramesh

Good grief, that should be the default!

sidharthramesh commented 2 years ago

Yes. I think this should be the default too

TranquilMarmot commented 1 month ago

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());