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

[BUG] Circular depedency when using vite and frontegg-react #1022

Open
drdaemos opened this issue Sep 8, 2023 · 8 comments
Open

[BUG] Circular depedency when using vite and frontegg-react #1022

drdaemos opened this issue Sep 8, 2023 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@drdaemos
Copy link

drdaemos commented Sep 8, 2023

Describe the bug
Running vite build fails on a npm package that depends on @frontegg/frontegg-react v5.0.50 with error:

Error: Circular dependency: ../../../node_modules/@frontegg/redux-store/auth/LoginState/saga.js -> ../../../node_modules/@frontegg/redux-store/auth/SignUp/saga.js -> ../../../node_modules/@frontegg/redux-store/auth/LoginState/saga.js

To Reproduce
Have a JavaScript npm package similar to the following template:

{
  ...
  "type": "module",
  "scripts": {
    "build": "vite build",
  },
  "dependencies": {
    "@frontegg/react": "v5.0.50",
  },
  "devDependencies": {
    "vite": "^4.4.9",
  }
  ...

Have the following code in your package source files:

import { FronteggProvider, useAuth, useLoginWithRedirect } from '@frontegg/react'

Expected behavior
I expect vite build to run without issues.

Additional context

Here is the build error log:

Circular dependency: ../../../node_modules/@frontegg/redux-store/auth/LoginState/saga.js -> ../../../node_modules/@frontegg/redux-store/auth/SignUp/saga.js -> ../../../node_modules/@frontegg/redux-store/auth/LoginState/saga.js
error during build:
Error: Circular dependency: ../../../node_modules/@frontegg/redux-store/auth/LoginState/saga.js -> ../../../node_modules/@frontegg/redux-store/auth/SignUp/saga.js -> ../../../node_modules/@frontegg/redux-store/auth/LoginState/saga.js
    at Object.onwarn (file:///home/../services/users/frontend-user/vite.config.ts.timestamp-1694170546515-ab39cd971c5ef.mjs:16:31)
    at onwarn (file:///home/../node_modules/@vitejs/plugin-react/dist/index.mjs:236:40)
    at onRollupWarning (file:///home/../node_modules/vite/dist/node/chunks/dep-df561101.js:48171:9)
    at onwarn (file:///home/../node_modules/vite/dist/node/chunks/dep-df561101.js:47902:13)
    at file:///home/../node_modules/rollup/dist/es/shared/node-entry.js:24194:13
    at Object.logger [as onLog] (file:///home/../node_modules/rollup/dist/es/shared/node-entry.js:25867:9)
    at Graph.sortModules (file:///home/../node_modules/rollup/dist/es/shared/node-entry.js:25766:26)
    at Graph.build (file:///home/../node_modules/rollup/dist/es/shared/node-entry.js:25654:14)
    at async file:///home/../node_modules/rollup/dist/es/shared/node-entry.js:26615:13
    at async catchUnfinishedHookActions (file:///home/../node_modules/rollup/dist/es/shared/node-entry.js:25827:16)
npm ERR! Lifecycle script `build` failed with error: 
@drdaemos drdaemos added the bug Something isn't working label Sep 8, 2023
@drdaemos drdaemos changed the title [BUG] [BUG] Circular depedency when using vite and frontegg-react Sep 8, 2023
@drdaemos
Copy link
Author

Is there any additional information I can provide to help debug this?

@doregg
Copy link
Contributor

doregg commented Sep 18, 2023

@drdaemos,

We're actively working on the issue you've reported, but as of now, we haven't been able to replicate it ourselves. It would be immensely helpful if you could share a sample project that demonstrates the problem you're encountering.

If providing an example project isn't feasible, could you please share some additional information with us? Specifically, we'd appreciate it if you could provide details about your Node.js version, your tsconfig.ts file, and any configuration you added.

@drdaemos
Copy link
Author

I will try to gather an example project and get back to you.

In general, judging by the compiled files - there definitely is a dependency between @frontegg/redux-store/auth/LoginState/saga.js and @frontegg/redux-store/auth/SignUp/saga.js: they both rely on at least one exported function from each other.

I'm not sure why it is not causing problems in the other envs, maybe Vite is doing some clever tree-shaking with the options that we have. If I don't build this with Vite and just use HMR to introduce the code dependent on the frontegg-react, it actually works fine.

@drdaemos
Copy link
Author

Here is the example project repo: https://github.com/drdaemos/frontegg-circular-issue

@doregg
Copy link
Contributor

doregg commented Sep 20, 2023

@drdaemos awesome! thanks. I realized that your Vite config file is different. When I use yours, I can reproduce it.
We are working on a fix.

@doregg
Copy link
Contributor

doregg commented Sep 21, 2023

Hey @drdaemos, it seems that your build is failing due to an internal configuration you have added to fail the build with every rollup warning:

  rollupOptions: {
    onwarn(warning) {
       throw Object.assign(new Error(), warning)
    },
  },

We will release a fixed version probably by the end of the week or early next week.

@artursvonda
Copy link

Any update on this?

@artursvonda
Copy link

By the way, we're now seeing

Circular dependency: ../../../node_modules/@frontegg/redux-store/auth/index.js -> ../../../node_modules/@frontegg/redux-store/auth/saga.js -> ../../../node_modules/@frontegg/redux-store/auth/SSOState/saga.js -> ../../../node_modules/@frontegg/redux-store/auth/LoginState/saga.js -> ../../../node_modules/@frontegg/redux-store/toolkit/index.js -> ../../../node_modules/@frontegg/redux-store/auth/index.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants