-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
SSR not working with cjs modules #13977
Comments
Start a new pull request in StackBlitz Codeflow. |
This looks to me like it's probably a usage/packaging issue. That library distributes CJS, but doesn't expose named exports with Does it work better if you change
Or maybe
I'm not exactly sure how to run your reproduction and test it, but I expect one of those would fix it. |
I think you are right. When yarn dev, ebuild handle the esm & cjs interop problem. // input
import { CopyToClipboard } from "react-copy-to-clipboard";
console.log(CopyToClipboard);
// output
var import_react_copy_to_clipboard = __toESM(require_lib(), 1);
console.log(import_react_copy_to_clipboard.CopyToClipboard); When yarn build & prod, "use strict";
var _require = require('./Component'),
CopyToClipboard = _require.CopyToClipboard;
CopyToClipboard.CopyToClipboard = CopyToClipboard;
module.exports = CopyToClipboard; I just try solutions provided by @benmccann , and it works for me. |
Great! I'll go ahead and close this then |
Describe the bug
I try to build ssr project, but cant to build production with cjs modules
And simple demo well works with hack ( ssr: {
noExternal:
mode === "production" ? ["react-copy-to-clipboard", "date-fns"] : [],
},), but crash with any error (filename.js not existed, but it already)
Reproduction
https://stackblitz.com/edit/github-vke2fz-67onp4?file=README.md
Steps to reproduce
yarn dev - failed
yarn run build
yarn run prod - failed (with noExternal its ok, but dev failed)
System Info
*
Used Package Manager
yarn
Logs
Validations
The text was updated successfully, but these errors were encountered: