I have an application built with NextJs (and React) and mobx-state-tree (but could be context or redux) as a package manager. All the stores are created and handled in an npm package called SMK (state management kit) that I created to make the sub-stores reusable in my mobile and web application.
How it works:
models
, actions
and views
on the SMK and export it as a module.yarn add @my-repo/smk
.But I need to run and publish the SMK locally to make it easier development. The solution I used to use is yalc.
Using yalc and running it locally this is the process:
yarn start
. (This will do nodemon --ignore src/index.ts -e js,ts,tsx,json --watch src/ --exec yalc push --scripts
)yalc add @my-repo/smk
. (This will add a dependency like "@my-repo/smk": "file:.yalc/@my-repo/smk"
).yarn build
and then yarn start
And voila! Everything is working perfect, any change I did locally on my SMK is working perfectly on the APP.
BUT, when I run yarn dev
that do next dev
as default of NextJs it doesn't work.
Error explanation: As I only added the setTestingState
and testingState
locally, it's saying that it doesn't exist.
Possible reason: The fast refresh is not refreshing the cache properly.
I've tried:
// @refresh reset
to force it, but didn't work.What is the solution/workaround to solve this issue with yarn dev
and yalc
?
Looks like it's a bug on NextJs and we can find some devs asking to NextJs to allow us to disable the Fast Refresh, and looks like they don't care or just don't have the intention to change it.
So, I found a third-party library, next-remote-watch, that is solving this issue for me. Basically, is an alternative script to use instead of next dev
and it will do a quick and simply build and active a watcher.
At package.json
use
"scripts": {
"start": "next-remote-watch @my-repo/smk"
}