AppAuth-JS icon indicating copy to clipboard operation
AppAuth-JS copied to clipboard

Xhr.js ReferenceError: $ is not defined

Open StefanVrecic opened this issue 4 years ago • 7 comments

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 :)

StefanVrecic avatar Aug 04 '21 17:08 StefanVrecic

Did you npm install after cloning the repository ?

tikurahul avatar Aug 04 '21 18:08 tikurahul

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.

StefanVrecic avatar Aug 05 '21 02:08 StefanVrecic

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)

foxtree avatar Aug 25 '21 20:08 foxtree

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

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

sidharthramesh avatar Oct 02 '21 14:10 sidharthramesh

Thanks @sidharthramesh

Good grief, that should be the default!

tpluscode avatar Oct 15 '21 11:10 tpluscode

Yes. I think this should be the default too

sidharthramesh avatar Oct 15 '21 12:10 sidharthramesh