-
Notifications
You must be signed in to change notification settings - Fork 259
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
TypeError: okta_auth_js_1.default is not a constructor #128
Comments
Tried few tweaks but no luck. New set of issues/observations.Error | TS2580 | (TS) Cannot find name 'require'. Do you need to install type definitions for node? Try |
@MyShah1 Thanks for the report. Could you share here the relevant piece of code from |
Here's the code snippet, last line thows the error.
|
@MyShah1 Are you using the latest version of Use:
more information is here: https://github.com/okta/okta-auth-js#using-the-npm-module |
yes, I have already updated that, that is how I have coded but still I have been getting the error.import { OktaAuth } from '@okta/okta-auth-js'; |
The error
Indicates it is trying to use "default" import. This would happen by using a import { OktaAuth } from '@okta/okta-auth-js' should not produce this error since it is using a named export. The other possibility is a version conflict. The internal version of Alternatively you can access the React SDK's internal auth-js instance, it is available as a property named |
Here's my import statementsimport { OktaAuth } from '@okta/okta-auth-js';
|
can you please share some more details on how to access _oktaAuth? thanks |
@MyShah1 I notice you imported both Also wondering is there any specific reason that you want to use those two SDKs together? |
@shuowu I believe both I have this in my import React, { Component } from 'react';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import { OktaAuth } from '@okta/okta-auth-js';
import { LoginCallback, Security } from '@okta/okta-react';
import Home from './Home';
const oktaAuth = new OktaAuth({
issuer: 'https://dev-133320.okta.com/oauth2/default',
clientId: '0oa5nak5fmUbfT3O3357',
redirectUri: window.location.origin + '/callback'
});
class App extends Component {
render() {
return (
<Router>
<Security oktaAuth={oktaAuth}>
<Route path="/" exact={true} component={Home}/>
<Route path="/callback" component={LoginCallback}/>
</Security>
</Router>
);
}
}
export default App; In my import React from 'react';
import ReactDOM from 'react-dom';
import { act } from 'react-dom/test-utils';
import App from './App';
let container;
beforeEach(() => {
container = document.createElement('div');
document.body.appendChild(container);
});
afterEach(() => {
document.body.removeChild(container);
container = null;
});
test('renders learn react link', async () => {
await act(async () => {
ReactDOM.render(<App/>, container);
});
const linkElement = container.querySelector('a');
expect(linkElement.textContent).toBe('Learn React');
}); When I run
Any idea how to fix it? |
For those seeing this issue in tests, you may need to adjust your config: https://github.com/okta/okta-react/blob/master/jest.config.js#L23
|
Thanks @aarongranick-okta! Adding this snippet to my package.json fixed the tests:
|
@MyShah1 were you able to resolve your issue, or can we provide further assistance? |
@mraible - I am facing exact issue while running my app locally (dint try tests) - were you able to fix this issue? |
@niteshchaudhary This error usually means that the commonJS version of the library is loaded, but the calling code is expecting ES. This can happen easily with If you are using ES syntax (recommended), it should be:
Note that If using commonJS (not recommended unless this is a NodeJS application)
|
@aarongranick-okta - I am using curly braces. |
@niteshchaudhary I'm assuming you are using the latest version of okta-auth-js (4.7.x). Are you using a yarn or lerna workspace or otherwise hoisting modules such that it is possible it is using an older version of the module? What are you using for bundling? typescript, babel, webpack? Any of these tools should be able to find the correct "browser" or "module" entrypoint, but if the bundler is confused, you may have to point it directly to the module entry:
(hopefully it should not come to this) |
@aarongranick-okta - I guess, I got some hold of the issue. and I changed my
reference: https://github.com/okta/okta-auth-js#transformauthstate |
@niteshchaudhary |
Hey guys, adding this worked
However, I'm curios to know if this makes a real call out to the issuer url? I'd rather not be making real network requests during tests and just mock the auth object itself instead which is passed into the |
Is there any update on this? I'm trying to test App.tsx file containing following code:
And the test is
I keep getting
However if I change the configuration to point to
|
@nikhileshncyb // broadcast-channel should not detect node environment
// https://github.com/pubkey/broadcast-channel/blob/master/src/util.js#L61
process[Symbol.toStringTag] = 'Process'; |
hey, did anyone manage to run it? I'm using jest, I've already done the mapping of the module and the solution above and still nothing |
+1, The workaround is not working for me as well. I am in an non-ejected create-react-app, which requires putting jest setup code in I have the line
I know there have been new releases in both okta-auth-js and broadcast-channel since a year ago, any of those changes effect this? |
React, redux with Visual studio enterprise, created default react app using Visual studio and followed step by step user guide for react application. While rendering Login Page I encountered this error:
LoginForm.tsx:18 Uncaught TypeError: okta_auth_js_1.default is not a constructor
at new LoginForm (LoginForm.tsx:18)
at constructClassInstance (react-dom.development.js:14185)
at updateClassComponent (react-dom.development.js:18394)
at beginWork$1 (react-dom.development.js:20161)
at HTMLUnknownElement.callCallback (react-dom.development.js:336)
at Object.invokeGuardedCallbackDev (react-dom.development.js:385)
at invokeGuardedCallback (react-dom.development.js:440)
at beginWork$$1 (react-dom.development.js:25738)
at performUnitOfWork (react-dom.development.js:24662)
at workLoopSync (react-dom.development.js:24638)
at performSyncWorkOnRoot (react-dom.development.js:24237)
at react-dom.development.js:12180
at unstable_runWithPriority (scheduler.development.js:818)
at runWithPriority$2 (react-dom.development.js:12130)
at flushSyncCallbackQueueImpl (react-dom.development.js:12175)
at flushSyncCallbackQueue (react-dom.development.js:12163)
at discreteUpdates$1 (react-dom.development.js:24390)
at discreteUpdates (react-dom.development.js:1442)
at dispatchDiscreteEvent (react-dom.development.js:5885)
The text was updated successfully, but these errors were encountered: