swr icon indicating copy to clipboard operation
swr copied to clipboard

Multiple swr version conflict

Open zombieJ opened this issue 1 year ago • 1 comments

Bug report

Description / Observed Behavior

When deps use different version swr like v1 & v2. It will throw error:

截屏2022-12-23 16 41 02

It's caused by the export use package name instead of relative path and swr self package.json not deps on swr:

https://github.com/vercel/swr/blob/main/core/index.ts#L6

It should be:

  export { SWRConfig, unstable_serialize } from './use-swr'
- export { useSWRConfig } from 'swr/_internal'
+ export { useSWRConfig } from '../_internal'
- export { mutate } from 'swr/_internal'
+ export { mutate } from '../_internal'
- export { preload } from 'swr/_internal'
+ export { preload } from '../_internal'

Or just publish @swr/internal package and add in package.json deps.

Expected Behavior

Not break.

Repro Steps / Code Example

https://stackblitz.com/edit/react-ts-dhpe9y?file=package.json,App.tsx

You can see the error to tell swr v2 try to find swr/_internal with v1:

Error in turbo_modules/[email protected]/core/dist/index.js

The entrypoint for 'swr' could not successfully be resolved. The file '/turbo_modules/[email protected]/_internal' does not exist. Please log an issue with the package author or check for an updated version of the package.

Additional Context

zombieJ avatar Dec 23 '22 09:12 zombieJ

+1

afc163 avatar Dec 23 '22 09:12 afc163