-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Version 8.x does not work on nodejs (commonjs) #494
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
Comments
you should be able to do react-spring/web.cjs (hooks) or /renderprops.cjs (classbased api), does this work? |
mhh, not with (my) webpack setup at least, it picks (depending on node/web) the Is it not possible to also export the class based api in the main file? |
web.cjs uses require though, you can look into it - there's no import statement. same for /renderprops.cjs. there's no change there, though. the modules export was always esm, and cjs is given optionally as main. You can pick either one. code splitting isn't affected, only tree shaking. |
Yes, the cjs files are fine and work, sorry, I meant tree shaking, this would not work anymore I guess? |
treeshaking doesn't work with cjs. where do you use react-spring? is this something like next or gatsby? |
Yes, something like next (custom). It's of course possible to just add an alias for those imports when compiling the server side. |
Confirmed that |
If next can't handle esm, you need to do: import { Spring } from 'react-spring/renderprops.cjs'. But that isn't new, cjs was introduced i think in version 5 or so. |
It can be handled on client side, but not on the server side, dependencies in node_modules normally don't go through webpack so they won't be transpiled (but are marked as externals). It only correctly determines esm/commonjs when |
Doing Throws the famous |
Importing like |
Anyone know how to do this in typescript? Had to rename renderprops.cjs to renderprops.js in 'node_modules/react-spring' to get it to work. |
How does typescript work in that regard? We have the following: https://github.com/react-spring/react-spring/tree/master/types Does it need extra types for the .cjs files? Also, is there a reason these SSR type frameworks don't support modules? How do you handle other libs and imports that don't support cjs? |
As I've said above, renaming ...cjs.js to ...js did it for me. Before that I goth this error
This is the first library I've run into that didn't support cjs... I guess it makes sense since it is a front-end library, but then again SSR is a thing for react. |
The lib does support cjs, but types are 100% made by contributions, so that part seems seems to have been let out until now. So just duplicating the type files is enough? for instance:
can type files at least do imports/exports? |
That could be a solution too. Just created...
|
perfect, i've already done this now - next patch will have it. :) |
Apologies if this goes beyond the scope of this issue, but I just ran into this problem myself (only while running Jest on files which use Taking a step back, though, is the recommended fix just to use |
the lib is declared as a module in the docs and package.json, and the currents docs also explain .cjs now (https://www.react-spring.io). node doesn't handle esm yet, i guess you would always want to use commonjs in such cases, that is the de facto standard for node. |
Whoops, sorry! I hadn't seen the docs at http://react-spring.io, only the docs sites (http://react-spring-renderprops.surge.sh/, https://react-spring.surge.sh/#/). |
The 8.x branch of react-spring stopped working for me on nodejs. It seems like all modules are now using
import
(ES Modules). I think a commonjs version (withrequire
) should be build as well and published to npm, otherwise it has to be transpiled before on the server.The text was updated successfully, but these errors were encountered: