frontegg / frontegg-react

Frontegg-React is pre-built Component for faster and simpler integration with Frontegg services.
https://docs.frontegg.com/
MIT License
32 stars 10 forks source link

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

Open drdaemos opened 1 year ago

drdaemos commented 1 year ago

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 commented 1 year ago

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

doregg commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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

doregg commented 1 year ago

@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 commented 1 year ago

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 commented 11 months ago

Any update on this?

artursvonda commented 11 months ago

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