Closed Clee681 closed 3 years ago
@Clee681 Thanks for posting!
I will ask our SDK engineers to take a look and comment.
cc: @aarongranick-okta @shuowu-okta
I confirm the issue when importing 5.0.2.
Here is a PR to fix this: #786
@Clee681 Thanks for reporting the issue, we will release a patch for it and get you updated in this thread.
@hirako2000 Thanks for your contribution! As there still are some other missing modules in dependencies
, I'll take this issue over and do more test on it.
Internal Ref: OKTA-402553
@shuowu-okta we are getting a similar issue: Cannot find module '@peculiar/webcrypto' from 'node_modules/@okta/okta-auth-js/cjs/crypto/node.js'
Will this be included in the patch?
@jchabotamica Yep, you can check #805 for details.
One workaround before the patch release is to manually add modules atob
, btoa
and @peculiar/webcrypto
to your app.
Thanks @shuowu-okta!!
Patches released. You can find 5.1.1 and 5.0.3 on npm.
@shuowu-okta I'm seeing the below error on fresh install
3:36:13 PM [vite] new dependencies found: @okta/okta-auth-js, updating...
> node_modules/@peculiar/webcrypto/build/webcrypto.es.js:7:17: error: No matching export in "browser-external:crypto" for import "createCipheriv"
7 │ import crypto, { createCipheriv, publicEncrypt, privateDecrypt, constants } from 'crypto';
╵ ~~~~~~~~~~~~~~
> node_modules/@peculiar/webcrypto/build/webcrypto.es.js:7:33: error: No matching export in "browser-external:crypto" for import "publicEncrypt"
7 │ import crypto, { createCipheriv, publicEncrypt, privateDecrypt, constants } from 'crypto';
╵ ~~~~~~~~~~~~~
> node_modules/@peculiar/webcrypto/build/webcrypto.es.js:7:48: error: No matching export in "browser-external:crypto" for import "privateDecrypt"
7 │ import crypto, { createCipheriv, publicEncrypt, privateDecrypt, constants } from 'crypto';
╵ ~~~~~~~~~~~~~~
> node_modules/@peculiar/webcrypto/build/webcrypto.es.js:7:64: error: No matching export in "browser-external:crypto" for import "constants"
7 │ import crypto, { createCipheriv, publicEncrypt, privateDecrypt, constants } from 'crypto';
╵ ~~~~~~~~~
> node_modules/@peculiar/webcrypto/build/webcrypto.es.js:8:9: error: No matching export in "browser-external:process" for import "version"
8 │ import { version } from 'process';
╵ ~~~~~~~
3:36:13 PM [vite] error while updating dependencies:
Error: Build failed with 5 errors:
node_modules/@peculiar/webcrypto/build/webcrypto.es.js:7:17: error: No matching export in "browser-external:crypto" for import "createCipheriv"
node_modules/@peculiar/webcrypto/build/webcrypto.es.js:7:33: error: No matching export in "browser-external:crypto" for import "publicEncrypt"
node_modules/@peculiar/webcrypto/build/webcrypto.es.js:7:48: error: No matching export in "browser-external:crypto" for import "privateDecrypt"
node_modules/@peculiar/webcrypto/build/webcrypto.es.js:7:64: error: No matching export in "browser-external:crypto" for import "constants"
node_modules/@peculiar/webcrypto/build/webcrypto.es.js:8:9: error: No matching export in "browser-external:process" for import "version"
at failureErrorWithLog (/Users/clee/Development/code/mlbam/vfx/web/node_modules/esbuild/lib/main.js:1446:15)
at /Users/clee/Development/code/mlbam/vfx/web/node_modules/esbuild/lib/main.js:1128:28
at runOnEndCallbacks (/Users/clee/Development/code/mlbam/vfx/web/node_modules/esbuild/lib/main.js:918:63)
at buildResponseToResult (/Users/clee/Development/code/mlbam/vfx/web/node_modules/esbuild/lib/main.js:1126:7)
at /Users/clee/Development/code/mlbam/vfx/web/node_modules/esbuild/lib/main.js:1233:14
at /Users/clee/Development/code/mlbam/vfx/web/node_modules/esbuild/lib/main.js:609:9
at handleIncomingPacket (/Users/clee/Development/code/mlbam/vfx/web/node_modules/esbuild/lib/main.js:706:9)
at Socket.readFromStdout (/Users/clee/Development/code/mlbam/vfx/web/node_modules/esbuild/lib/main.js:576:7)
at Socket.emit (node:events:365:28)
at Socket.emit (node:domain:470:12)
@Clee681 Which version of okta-auth-js are you using? Also, looks like you are using the CommonJS bundle(cjs), are you working on a server side app?
@shuowu-okta I'm using v5.1.1
in SvelteKit (which does do Server Side Rendering). I think I identified the bug being a Vite issue based on this https://github.com/sveltejs/kit/issues/1570.
@shuowu-okta Any ideas if this is an esm vs. cjs issue in okta-auth-js
?
@shuowu-okta I was able to track my issue down to the @peculiar/webcrypto
dependency. I filed an issue with their project, but it seems like the library does not work in the browser (i.e. it depends on node objects crypto
and process
). Hopefully, I get a response from the team. I think this will be an issue for anyone attempting to use okta-auth-js
in SSR setups w/ Vite.
@Clee681 This module is used as a fallback for node env, browser side depends on the Web_Crypto_API.
So your app is doing server side rendering, and the bundler picked the cjs bundle of okta-auth-js, then in which step you see the error above?
@shuowu-okta Gotcha. I created a quick bare bones reproduction here https://github.com/Clee681/okta-esm-module-repro.
Steps to view the error:
npm i
npm run dev
# you should see the errors in the terminal
I only added one line to the base template which was the below:
I appreciate you responding so quickly!
@Clee681 I think this issue happens when vite
starts doing deps optimization. You probably can add some custom config there to bypass the @peculiar/webcrypto
. If you app is just a SPA and runs in modern browsers, then this module won't be needed. https://vitejs.dev/config/#dep-optimization-options
Also another work can be using the okta-auth-js artifact from Okta global CDN ( v5.1.1 ) to avoid the bundler issue.
Thanks for looking into it. I'll try bypassing any optimization via the Vite config options to see if that fixes the issue in the repro project.
On first thought, I'm wondering if that solution will work for my SvelteKit app though. Based on my current implementation, I use OktaAuth
both on the client and server side. For example, the backend uses OktaAuth.signIn
and the frontend uses OktaAuth.tokenManager
.
@shuowu-okta I think I finally identified the issue. Vite doesn't seem to like how okta-auth-js
switches between the node and browser dependencies (i.e. using webpack to switch between node
and browser
files).
I have a thread in their repository so will report back what they say. I suspect this will be a bigger issue as Vite is gaining a lot of traction in the React, Vue, and Svelte worlds.
https://github.com/vitejs/vite/issues/3736#issuecomment-858648751
@Clee681 Instead of fighting against vite
, maybe you can try use the commonJS bundle on the server side, then use the CDN artifact (add Githubissues.
Hello,
When importing
OktaAuth
from5.0.2
using nodev14.15.0
, I get the following module error.Edit: Confirmed that this is not an issue in
4.9.2