web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API ๐Ÿฆ€๏ธ
https://rspack.dev
MIT License
9.37k stars 543 forks source link

[Bug]: Rsbuild: HarmonyLinkingError: export 'Layout' (imported as 'Layout') was not found in '@rive-app/react-canvas' (possible exports: __esModule, default, useRive, useStateMachineInput) #7022

Closed GiancarlosIO closed 2 months ago

GiancarlosIO commented 3 months ago

System Info

System: OS: macOS 12.5.1 CPU: (8) arm64 Apple M1 Memory: 343.16 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 20.13.1 - ~/.nvm/versions/node/v20.13.1/bin/node npm: 10.5.2 - ~/.nvm/versions/node/v20.13.1/bin/npm pnpm: 9.4.0 - ~/.nvm/versions/node/v20.13.1/bin/pnpm Browsers: Brave Browser: 119.1.60.118 Chrome: 126.0.6478.127 Safari: 15.6.1

Rsbuild: "@rsbuild/core": "0.7.10", "@rsbuild/plugin-react": "0.7.10",

Details

I'm getting an error when trying to use @rive-app/react-canvas. It looks like the exports from a common-js dependency (@rive-app/canvas) are not being resolved correctly ๐Ÿค” .

[rsbuild] File: /Users/user/Documents/project/project-frontend-apps/packages/compass.playroom/dist/AnimatedCoinRive/AnimatedCoinRive.js:1:1
[rsbuild]   ร— HarmonyLinkingError: export 'Fit' (imported as 'Fit') was not found in '@rive-app/react-canvas' (possible exports: __esModule, default, useRive, useStateMachineInput)
[rsbuild]     โ•ญโ”€[17:1]
[rsbuild]  17 โ”‚       autoplay: false,
[rsbuild]  18 โ”‚       layout: new Layout({
[rsbuild]  19 โ”‚         fit: Fit.Contain,
[rsbuild]     ยท              โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
[rsbuild]  20 โ”‚         alignment: Alignment.TopLeft
[rsbuild]  21 โ”‚       }),
[rsbuild]     โ•ฐโ”€โ”€โ”€โ”€
[rsbuild]
[rsbuild] File: /Users/user/Documents/project/project-frontend-apps/packages/compass.playroom/dist/AnimatedCoinRive/AnimatedCoinRive.js:1:1
[rsbuild]   ร— HarmonyLinkingError: export 'Alignment' (imported as 'Alignment') was not found in '@rive-app/react-canvas' (possible exports: __esModule, default, useRive, useStateMachineInput)
[rsbuild]     โ•ญโ”€[18:1]
[rsbuild]  18 โ”‚       layout: new Layout({
[rsbuild]  19 โ”‚         fit: Fit.Contain,
[rsbuild]  20 โ”‚         alignment: Alignment.TopLeft
[rsbuild]     ยท                    โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
[rsbuild]  21 โ”‚       }),
[rsbuild]  22 โ”‚       useOffscreenRenderer: true,
[rsbuild]     โ•ฐโ”€โ”€โ”€โ”€
[rsbuild]
[rsbuild] File: /Users/user/Documents/project/project-frontend-apps/packages/compass.playroom/dist/AnimatedStaticCoinRive/AnimatedStaticCoinRive.js:1:1
[rsbuild]   ร— HarmonyLinkingError: export 'Layout' (imported as 'Layout') was not found in '@rive-app/react-canvas' (possible exports: __esModule, default, useRive, useStateMachineInput)
[rsbuild]     โ•ญโ”€[24:1]
[rsbuild]  24 โ”‚       src: RIVE_ANIMATION_STATIC_COIN_URL,
[rsbuild]  25 โ”‚       artboard: ANIMATED_STATIC_COIN_ARTBOARD,
[rsbuild]  26 โ”‚       layout: new Layout({
[rsbuild]     ยท                   โ”€โ”€โ”€โ”€โ”€โ”€
[rsbuild]  27 โ”‚         fit: Fit.Cover,
[rsbuild]  28 โ”‚         alignment: Alignment.Center
[rsbuild]     โ•ฐโ”€โ”€โ”€โ”€
[rsbuild]
[rsbuild] File: /Users/user/Documents/project/project-frontend-apps/packages/compass.playroom/dist/AnimatedStaticCoinRive/AnimatedStaticCoinRive.js:1:1
[rsbuild]   ร— HarmonyLinkingError: export 'Fit' (imported as 'Fit') was not found in '@rive-app/react-canvas' (possible exports: __esModule, default, useRive, useStateMachineInput)
[rsbuild]     โ•ญโ”€[25:1]
[rsbuild]  25 โ”‚       artboard: ANIMATED_STATIC_COIN_ARTBOARD,
[rsbuild]  26 โ”‚       layout: new Layout({
[rsbuild]  27 โ”‚         fit: Fit.Cover,
[rsbuild]     ยท              โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
[rsbuild]  28 โ”‚         alignment: Alignment.Center
[rsbuild]  29 โ”‚       }),

The error says that @rive-app/react-canvas doesn't have the exports of Layout and other modules but it isn't true. These modules, like Layout, are re-exported from @rive-app/canvas's rive.js file.

...
export { useRive, useStateMachineInput, useResizeCanvas, useRiveFile , RiveProps };
export { RiveState, UseRiveParameters, UseRiveFileParameters, UseRiveOptions } from './types';
export * from '@rive-app/canvas';  // <= this is re-exporting Layout, Alignment, Fit and other modules not found by rspack.

Maybe rsbuild/rspack is deleting the export * from '@rive-app/canvas'? ๐Ÿค”

Reproduce link

https://codesandbox.io/p/devbox/rsbuild-rive-app-bug-cyjfzp

Reproduce Steps

  1. Go to the sanbox: https://codesandbox.io/p/devbox/rsbuild-rive-app-bug-cyjfzp
  2. You will see the error

image

f312213213 commented 3 months ago

Hi, thanks for quick responding, but I think the same error still exist, this time I'm using the @tanstack/react-query lib and the case is:

import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

will have the following error message:

ร— HarmonyLinkingError: export 'QueryClient' (imported as 'QueryClient') was not found in '@tanstack/react-query' (possible exports: Hydrate, IsRestoringProvider, QueryClientProvider, QueryErrorResetBoundary, __esModule, defaultContext, useHydrate, useInfiniteQuery, useIsFetching, useIsMutating, useIsRestoring, useMutation, useQueries, useQuery, useQueryClient, useQueryErrorResetBoundary)

but QueryClient is re-export from @tanstack/query-core actually

import './setBatchUpdatesFn';
export * from '@tanstack/query-core'; // re-export from this line
export * from './types';

I'm using "@rsbuild/core": "1.0.0-alpha.4" which depends on the latest rspack, version: "1.0.0-alpha.1".

GiancarlosIO commented 3 months ago

in my case, it was fixed so THANKS @ahabhgk !

But yes @f312213213 , looks like rspack somehow is failing when a library re-exports all modules from an internal dependency ๐Ÿค”

@ahabhgk do you know if it's a bug in rspack itself? or maybe the libraries (like react query) are not following the standard? ๐Ÿค”

f312213213 commented 3 months ago

Additional information: When I use "@rsbuild/core": "0.5.9", everything works fine.

ahabhgk commented 2 months ago

@f312213213 I can't reproduce in my local, could you provide a minimal reproduce?

f312213213 commented 2 months ago

Hi @ahabhgk ,The following link is my minimal reproduce.

https://codesandbox.io/p/devbox/rsbuild-rive-app-bug-forked-mnlp5y