react-spring: @react-spring/core or @react-spring/three production errors
🐛 Bug Report
Hi, i’m using these to animate R3F components, but I do not run into this in development. The issue only occurs in production:
Uncaught TypeError: r.willAdvance is not a function
at 9cfe2b4608e7231bacc0d7d7deffe07ef300d220.20fefe92f1d342a18960.js:1
at Module.d (9cfe2b4608e7231bacc0d7d7deffe07ef300d220.20fefe92f1d342a18960.js:1)
at a.b.advance (9cfe2b4608e7231bacc0d7d7deffe07ef300d220.20fefe92f1d342a18960.js:1)
at 9cfe2b4608e7231bacc0d7d7deffe07ef300d220.20fefe92f1d342a18960.js:1
at 28ddf37e733bed61e8c6ac53a0464422aa01203b.0544bc5f695fe9930e09.js:1
at Array.forEach (<anonymous>)
at xe (28ddf37e733bed61e8c6ac53a0464422aa01203b.0544bc5f695fe9930e09.js:1)
To Reproduce:
Here is the code example i’m trying to run, and again, I want to stress this only happens in production
import React, { useRef } from 'react';
import { Canvas, useFrame } from 'react-three-fiber';
import { useSpring } from '@react-spring/core';
import { a } from '@react-spring/three';
import styled from '@emotion/styled';
const endless = true;
const Cube = () => {
const m: any = useRef();
useFrame(() => {
m.current.rotation.y += 0.01;
});
const { scale, color } = useSpring({
from: { scale: [1, 1, 1], color: '#17bebb' },
to: async next => {
while (endless) {
await next({ scale: [4, 4, 4], color: '#FAD8D6' });
await next({ scale: [1, 1, 1], color: '#17bebb' });
await next({ scale: [3, 3, 3], color: '#CD5334' });
await next({ scale: [2, 2, 2], color: '#EDB88B' });
await next({ scale: [1, 1, 1], color: '##17bebb' });
}
}
});
return (
<a.mesh ref={m} scale={scale}>
<boxBufferGeometry attach="geometry" args={[1, 1, 1]} />
<a.meshStandardMaterial attach="material" color={color} />
</a.mesh>
);
};
const AnimatingWithReactSpring = () => {
return (
<Container>
<Canvas>
<ambientLight position={[1, 1, 1]} />
<Cube />
</Canvas>
</Container>
);
};
const Container = styled.div`
border: 1px solid #ccc;
border-radius: 5px;
`;
Expected behavior
I expect it to run well, just like it does in development
Environment
- “@react-spring/core”: “^9.0.0-rc.3”
- “@react-spring/three”: “^9.0.0-rc.3”
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 59
- Comments: 93 (9 by maintainers)
Commits related to this issue
- chore: fix webpack to v4.43.0 so as to avoid errors in react-spring This is a known issue in react-spring, and will be fixed in the next RC release. [see this](https://github.com/react-spring/react-s... — committed to FuelRats/fuelrats.com by UncleClapton 4 years ago
- fix: patch react-spring by removing sideEffects false https://github.com/pmndrs/react-spring/issues/1078#issuecomment-664036914 — committed to newrelic/docs-website by jerelmiller 4 years ago
- Patch react-spring for now (bug) See https://github.com/pmndrs/react-spring/issues/1078 — committed to pixijs/pixi-react by inlet 4 years ago
- Patch react-spring for now (bug) See https://github.com/pmndrs/react-spring/issues/1078 — committed to pixijs/pixi-react by inlet 4 years ago
- Patch react-spring for now (bug) See https://github.com/pmndrs/react-spring/issues/1078 — committed to pixijs/pixi-react by inlet 4 years ago
- fix: react-spring production issue https://github.com/pmndrs/react-spring/issues/1078 — committed to davidballester/a-dirty-trail-webapp by davidballester 4 years ago
- patch react-use-gesture, pin webpack try to work around issue: https://github.com/pmndrs/react-spring/issues/1078 — committed to xiel/wheel-gestures by xiel 4 years ago
- next try try to work around issue: https://github.com/pmndrs/react-spring/issues/1078 — committed to xiel/wheel-gestures by xiel 4 years ago
- fix: react-spring error willAdvance is not a function, try III issue: https://github.com/pmndrs/react-spring/issues/1078 — committed to xiel/wheel-gestures by xiel 4 years ago
- fix: react-spring error willAdvance is not a function issue: https://github.com/pmndrs/react-spring/issues/1078 — committed to xiel/wheel-gestures by xiel 4 years ago
- fix: react-spring error willAdvance is not a function issue: https://github.com/pmndrs/react-spring/issues/1078 — committed to xiel/wheel-gestures by xiel 4 years ago
- fix: react-spring error willAdvance is not a function issue: https://github.com/pmndrs/react-spring/issues/1078 — committed to xiel/wheel-gestures by xiel 4 years ago
- Patch react-spring production bug https://github.com/pmndrs/react-spring/issues/1078\#issuecomment-663635523 — committed to devhubapp/devhub by brunolemos 4 years ago
- Add patch-package as devDependency for @atomic-reactor/admin reactium plugin. Create patch for react-spring. These heroics brought to you by the sort of helpful, sort of unhelpful, response to https:... — committed to ReactiumCore/Reactium-Admin-Plugins by jdillick 4 years ago
- Try adding react-spring side effects https://github.com/pmndrs/react-spring/issues/1078#issuecomment-713444083 — committed to mattrossman/breathing-dots-tutorial by mattrossman 4 years ago
- Try adding react-spring side effects https://github.com/pmndrs/react-spring/issues/1078#issuecomment-713444083 — committed to mattrossman/breathing-dots-tutorial by mattrossman 4 years ago
- patch react-spring (#6) pmndrs/react-spring#1078 — committed to alexichristakis/portfolio-website by alexichristakis 4 years ago
- patch prpravlen, ko daš npm install https://github.com/pmndrs/react-spring/issues/1078#issuecomment-692000408 — committed to lukaprsina/drive by lukaprsina 3 years ago
- Fix react-spring error In prod only we get the following error: ``` TypeError: r.willAdvance is not a function ``` Hopefully fixed by this workaround: https://github.com/pmndrs/react-spring/issues/1... — committed to ianobermiller/climate-compare by ianobermiller 3 years ago
- Fix Tooltips on Production `react-spring`, which handles the tooltip movement for Nivo, has a known issue with tooltips not correctly following the cursor - see https://github.com/pmndrs/react-spring... — committed to azavea/fb-gender-survey-dashboard by TaiWilkin 3 years ago
Okay so, I tried many of the fixes here, but none of them work.
patch-package
looked really promising, but trying to run it after making the changes returns:Has anyone actually been able to fix this? Is there a development branch that we can use in the meantime?
EDIT:
So I tried a bunch of different stuff until I noticed that the
patch
files create bypatch-package
had a bunch of stuff in them that hadn’t been changed and I didn’t need to be changed, this prompted me to try to remove everything and keep the bare minimum so that my files looked something like this:I then tried installing again and it worked!
So here’s an actual guide on fixing this:
node_modules/@react_spring
(notnode_modules/react_spring
)package.json
in the included folders (animated, core, native, shared, three, web, zdog)npx patch-package --exclude 'nothing' @react-spring/<folder>
, where<folder>
is one ofanimated, core, native, shared, three, web, zdog
eachpatches/
"sideEffects": false
(so that it looks like the example above)"postinstall": "patch-package"
to your scripts inpackage.json
npm install
Here’s hoping we get a new RC soon!
In case it helps anyone else, I wanted as light-touch a solution as possible since (hopefully 🙏 ) we’ll get an rc4 soon. Personally I’m using unejected CRA 4, but this should be generic.
Add a script to your root
package.json
, and run it onpostinstall
:(NB: Won’t generally work on windows for obvious reasons, but should be mac and linux compatible)
The issue was that
"sideEffects": false
was being used when it shouldn’t be, causingGlobals.assign
calls to be tree-shaked. Will be fixed in next RC. 👍For the record, even with the potential simplicity of using patch-package, this effort is vastly more complex for projects than simply publishing an 9.0.0-rc.4 with this fix.
patch-package (and a like strategy) suffers from some fragile build context problems. It is easy to enact this, have it work locally, and fail on a remote build system.
Such is the case for my project and building on heroku. Their devDependency phase of build applies this patch correctly, only to reinstall the package again after pruning devDependencies, and this time patch-package fails due to slightly different working directory context.
While this sort of issue isn’t really the fault of react-spring, it could be totally avoidable (this whole work-around would be as well) with such a low effort action by the maintainer. Please, please with a cherry-on-top, npm publish 9.0.0-rc.4 with this trivial build fix.
If main branch is in a bad state, you could cut a hotfix branch off tag https://github.com/pmndrs/react-spring/releases/tag/v9.0.0-rc.3, apply fix, bump to v9.0.0-rc.4, and
npm publish
This would be so helpful. 🥺For people who’s using
react-spring
along with webpack, here’s a workaround I believe you can use inwebpack.config.js
before a newreact-spring
is out with the fix:@enkicoma I was able to adapt @chenxsan’s solution to work with Next 10.0.3 by adding a webpack config function to my next.config.js file:
This fixed the
TypeError: r.willAdvance is not a function
error on my production build.@CharlieHess @Emiliano-Bucci I ended up adding scpipt below in package.json postinstall hook. (
"postinstall": "node postinstall.js"
, + "replace-in-file in devDependencies)Could this not be released as a patch ? I think a lot of people are using the rc3 because it has been said that it’s more stable than 8.x, and since rc4 seems quite distant it might be a good idea to get really breaking things like this onto npm.
I can confirm that using NextJS with webpack > ^4.44.x is broken by this, in the mean time you can force webpack to ~4.43.x with resolutions in your package.json:
Thank you, you saved my day!!
I added theses script in
package.json
and it worked.Hope this issuse would be fixed in next version!
had the exact same error in production build only and using @iam4x solution helped me.
I’m hitting this in a similar environment (Next + r3f + react-spring) and none of the workarounds listed here work.
⛔
patch-package
to removesideEffects
for all spring packages ⛔webpack@4.4.3
⛔next@9.4.5-canary.43
It looks like:
I just had the same bug after bootstrapping a new create-react-app. Downgrading react 17.0.1 and react-scripts 4.0.0 back to 16.13.1 and 3.4.1 also works.
I can confirm that upgrading from NextJS
9.4.5-canary.45
to9.5.0
produces the same error for me as well.This works for me with Next 10 and next-images, variation on the above:
Confirm that this solution works, nice approach, the code looks much cleaner now 👍
@ivnaleta Try adding
--exclude
at the end of the command, it should work. Example:npx patch-package react-spring --exclude
I’m not using Gatsby. I’ve come across this using Nextjs
Confirm - it works! I asked for some help on discord and combined 3 things together with your one and finally:
next.config.js
Thank you for your help and Happy New year!
@jdillick Made a PR #1229 which should make this easy.
@ivnaleta You could manually remove
"sideEffects": false
from thepackage.json
of everynode_modules/@react-spring/*
directory, then use patch-package to auto-apply those changes whennode_modules
is re-installed.Otherwise, if you still want to build v9 locally, you can follow the Contributing Guide and let me know if something trips you up. 👍
I also get this when bundling with
webpack@5.0.0-beta.22
. I didn’t have enough time to dig further in to the issue and reverted towebpack@4.43.0
which works fine, but it seems to be around how webpack was importing modules.Thanks, got it working! If anyone is using craco this craco.config.js works:
And for the Windows platform, this is the PowerShell script to do the same thing.
@heyimalex small typo in your comment. second L1 in the second command is missing a hyphen
Commands to do @creativiii 's method mentioned here apart from setting up
patch-package
.Confirms that this works for those using CRA. many thanks
I faced this issue on Gatsby v2.24.91 two hours before go live time, ugh.
Thanks @creativiii, confirmed these steps worked for me.
Seeing the same with preact & create-react-app.
@aleclarson Is there a way to use patch-package? Because it seems that it doesn’t patch the changes that are only applied to the
package.json
😕I’m not opposed to waiting for a fix in the next version, any idea of when that might be?
The entirety of the code is in that snippet. You need to run it in with an application set to production mode. Also it seems like this is not the first time it has occured as a similar production issue mentioned here #1069
I think I’ve provided enough information. If you want to chase it down feel free, if not thats fine too. @aleclarson
@joshuaellis Hi! I’ve update
react-spring
to the latest version but still I’m getting this issue (of course I can fix it with the previous workaround), but just wanted to understand if this fix goes up in the version 9 or not 😃Scroll up!!! A contributor has already explained what’s the cause and there are literally a bunch of workarounds available.
Great stuff! Worked! 🎉
@enkicoma You’ll need to create a next.config.js file as described here: https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config
Thanks @chenxsan - that worked for me!
Thank you, @creativiii. Those steps worked perfectly. It’s possible patch-package has been updated as I didn’t have to do this step:
Thanks again for the detailed steps. We really appreciate it.
Confirming that removing
"sideEffects": false
from package.json fixed the issue for me. Thanks for the suggestion @aleclarson!Thanks for isolating this @aleclarson. Is there any timeline on the next RC?
That’s good to know! 😆
Can you share your
next.config.js
?Please provide a git repository that reproduces the issue. Thanks 👍