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

"default" is not exported by "../../node_modules/swr/core/dist/react-server.mjs", #2700

Closed
himself65 opened this issue Jun 30, 2023 · 2 comments

Comments

@himself65
Copy link
Contributor

Bug report

Description / Observed Behavior

What kind of issues did you encounter with SWR?

> nx run @affine/docs:build

vite v4.3.9 building SSR bundle for production...
transforming...
src/server-fns.ts (1:0) Error when using sourcemap for reporting an error: Can't resolve original location of error.
../../node_modules/flexsearch/dist/flexsearch.bundle.js (23:33) Use of eval in "../../node_modules/flexsearch/dist/flexsearch.bundle.js" is strongly discouraged as it poses security risks and may cause issues with minification.
../../node_modules/lottie-web/build/player/lottie.js (17010:32) Use of eval in "../../node_modules/lottie-web/build/player/lottie.js" is strongly discouraged as it poses security risks and may cause issues with minification.
✓ 2828 modules transformed.
✓ built in 12.83s
"default" is not exported by "../../node_modules/swr/core/dist/react-server.mjs", imported by "../../packages/component/src/components/image-preview-modal/index.tsx".
file: /home/runner/work/AFFiNE/AFFiNE/packages/component/src/components/image-preview-modal/index.tsx:23:7
21: import { Suspense, useCallback } from 'react';
22: import { useEffect, useRef, useState } from 'react';
23: import useSWR from 'swr';
           ^
24: 
25: import { useZoomControls } from './hooks/use-zoom';
file:///home/runner/work/AFFiNE/AFFiNE/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:2213
        base = Object.assign(new Error(base.message), base);
                             ^
Error [RollupError]: "default" is not exported by "../../node_modules/swr/core/dist/react-server.mjs", imported by "../../packages/component/src/components/image-preview-modal/index.tsx".
    at error (file:///home/runner/work/AFFiNE/AFFiNE/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:2213:30)
    at Module.error (file:///home/runner/work/AFFiNE/AFFiNE/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:13537:16)
    at Module.traceVariable (file:///home/runner/work/AFFiNE/AFFiNE/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:13962:29)
    at ModuleScope.findVariable (file:///home/runner/work/AFFiNE/AFFiNE/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:12480:39)
    at ReturnValueScope.findVariable (file:///home/runner/work/AFFiNE/AFFiNE/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:7038:38)
    at ChildScope.findVariable (file:///home/runner/work/AFFiNE/AFFiNE/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:7038:38)
    at Identifier.bind (file:///home/runner/work/AFFiNE/AFFiNE/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:8200:40)
    at CallExpression.bind (file:///home/runner/work/AFFiNE/AFFiNE/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:5806:23)
    at CallExpression.bind (file:///home/runner/work/AFFiNE/AFFiNE/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:9[76](https://github.com/toeverything/AFFiNE/actions/runs/5419519841/jobs/9852710763?pr=2939#step:4:77)6:15)
    at VariableDeclarator.bind (file:///home/runner/work/AFFiNE/AFFiNE/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:5[80](https://github.com/toeverything/AFFiNE/actions/runs/5419519841/jobs/9852710763?pr=2939#step:4:81)6:23) {
  binding: 'default',
  code: 'MISSING_EXPORT',
  exporter: '/home/runner/work/AFFiNE/AFFiNE/node_modules/swr/core/dist/react-server.mjs',
  id: '/home/runner/work/AFFiNE/AFFiNE/packages/component/src/components/image-preview-modal/index.tsx',
  url: 'https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module',
  pos: 515,
  loc: {
    column: 7,
    file: '/home/runner/work/AFFiNE/AFFiNE/packages/component/src/components/image-preview-modal/index.tsx',
    line: 23
  },
  frame: "21: import { Suspense, useCallback } from 'react';\n" +
    "22: import { useEffect, useRef, useState } from 'react';\n" +
    "23: import useSWR from 'swr';\n" +
    '           ^\n' +
    '24: \n' +
    "25: import { useZoomControls } from './hooks/use-zoom';",
  watchFiles: [
    '/home/runner/work/AFFiNE/AFFiNE/apps/docs/entries.ts',
    '/home/runner/work/AFFiNE/AFFiNE/apps/docs/package.json',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/waku/dist/router/server.js',
    '/home/runner/work/AFFiNE/AFFiNE/apps/docs/src/app.tsx',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/waku/dist/router/client.js',
    '/home/runner/work/AFFiNE/AFFiNE/apps/docs/src/components/sidebar/index.tsx',
    '/home/runner/work/AFFiNE/AFFiNE/apps/docs/src/server-fns.ts',
    '/home/runner/work/AFFiNE/AFFiNE/apps/docs/src/components/editor.tsx',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/waku/dist/client.js',
    '/home/runner/work/AFFiNE/AFFiNE/packages/component/package.json',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@blocksuite/editor/themes/affine.css',
    '/home/runner/work/AFFiNE/AFFiNE/packages/component/src/components/block-suite-editor/index.tsx',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/jotai/esm/react.mjs',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/yjs/dist/yjs.mjs',
    '/home/runner/work/AFFiNE/AFFiNE/apps/docs/src/atom.ts',
    '/home/runner/work/AFFiNE/AFFiNE/apps/docs/src/components/sidebar/save-to-local.tsx',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/react-server-dom-webpack/client.node.unbundled.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/jotai/esm/vanilla.mjs',
    '/home/runner/work/AFFiNE/AFFiNE/packages/jotai/package.json',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@blocksuite/global/dist/utils.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/react-dom/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/react-error-boundary/dist/react-error-boundary.esm.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@blocksuite/blocks/dist/models.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@blocksuite/store/dist/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/packages/jotai/src/index.ts',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/jotai/esm/index.mjs',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/CardActionArea/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/CardActions/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/CardContent/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/CardHeader/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/CardMedia/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/Checkbox/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/Chip/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/CircularProgress/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/ClickAwayListener/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/Collapse/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/Container/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/CssBaseline/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/darkScrollbar/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/Dialog/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/DialogActions/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/DialogContent/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/DialogContentText/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/DialogTitle/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/Divider/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/Drawer/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/Fab/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/Fade/index.js',
    '/home/runner/work/AFFiNE/AFFiNE/node_modules/@mui/material/FilledInput/index.js',
    ... 2734 more items
  ]
}

Expected Behavior

How did you expect SWR to behave here?

Compile successfully.

Repro Steps / Code Example

Or share your code snippet or a CodeSandbox link is also appreciated!

toeverything/AFFiNE#2939

Additional Context

SWR version: 2.2.0
React version: 18.3.0-canary-8ec962d82-20230623

@promer94
Copy link
Collaborator

promer94 commented Jun 30, 2023

It is more like a bundler bug. Your bundler picks the wrong entry point.

Maybe add use client to the top of your image-preview-modal component could solve this issue.

SWR works correctly with waku's default setup https://codesandbox.io/p/sandbox/waku-example-counter-forked-p4fp3d

@promer94 promer94 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 30, 2023
@himself65
Copy link
Contributor Author

See dai-shi/waku#96

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants