react-spring: Version 8.x does not work on nodejs (commonjs)
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 (with require
) should be build as well and published to npm, otherwise it has to be transpiled before on the server.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 20 (9 by maintainers)
Confirmed that
import { Spring } from 'react-spring/renderprops';
breaks next.js default setup because of ES modulesthe 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.
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:
/types/web.cjs.d.ts
can type files at least do imports/exports?
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.
treeshaking doesn’t work with cjs. where do you use react-spring? is this something like next or gatsby?