Open cmoulliard opened 9 months ago
!! There is still a big big issue as we got this error when frontend is started yarn start
ERROR in ../../../backstage-quarkus-plugins/node_modules/@material-ui/core/esm/SwipeableDrawer/SwipeArea.js 4:0-31
Module not found:
Error: Can't resolve 'react' in '/Users/cmoullia/code/openshift/backstage-quarkus-plugins/node_modules/@material-ui/core/esm/SwipeableDrawer'
The solution is maybe to perform a yarn install
within the project where plugin has been linked - https://backstage.io/docs/local-dev/linking-local-packages/
Temporary workaround is todo
From the github plugin project AND if we modify the module quarkus-console
, execute the following commands to copy the file files generated to the backstage app project
PLUGIN_NAME=quarkus-console
BACKSTAGE_APP_PATH=$HOME/code/openshift/fork-backstage-playground
yarn tsc; yarn build
cp -rf plugins/$PLUGIN_NAME/dist/ $BACKSTAGE_APP_PATH/node_modules/@qshift/plugin-$PLUGIN_NAME/dist
There is still an issue after we merged the PR #45 where react packages have been added as DevDependencies
Since we updated the plugins to use React 18 and playground has been bumped to 1.23.4, we got another error when we link the plugin within the playground backstage app => Cannot read properties of null (reading 'useContext')
Call Stack
useContext
backstage-quarkus-plugins/node_modules/react/cjs/react.development.js:1619:21
useVersionedContext
backstage-quarkus-plugins/node_modules/@backstage/version-bridge/dist/index.esm.js:59:59
useEntity
backstage-quarkus-plugins/node_modules/@backstage/plugin-catalog-react/dist/esm/useEntity-de64059a.esm.js:57:105
useK8sObjectsResponse
backstage-quarkus-plugins/plugins/quarkus-console/src/services/useK8sObjectsResponse.ts:21:90
QuarkusApplicationInfo
backstage-quarkus-plugins/plugins/quarkus-console/src/components/QuarkusApplicationInfo.tsx:39:123
renderWithHooks
node_modules/react-dom/cjs/react-dom.development.js:16305:18
mountIndeterminateComponent
node_modules/react-dom/cjs/react-dom.development.js:20069:13
beginWork
node_modules/react-dom/cjs/react-dom.development.js:21582:16
HTMLUnknownElement.callCallback
node_modules/react-dom/cjs/react-dom.development.js:4164:14
Object.invokeGuardedCallbackDev
node_modules/react-dom/cjs/react-dom.development.js:4213:16
Idea ? @iocanel
I did some researches and was able to find an approach which is working:
yarn dev
runs and can be visualizedDipatcher is null
due to react versions conflictInstructions
// From plugins project
rm -rf node_modules
ln -s $HOME/PATH_TO_BACKSTAGE_PLAYGROUND/node_modules ./node_modules
// From $HOME/PATH_TO_BACKSTAGE_PLAYGROUND
rm -rf node_modules
# Edit the packages/app/package.json to add/replace the following dependencies
"@qshift/plugin-quarkus": "link:../../../BACKSTAGE_QUARKUS_PLUGINS/plugins/quarkus",
"@qshift/plugin-quarkus-console": "link:../../../BACKSTAGE_QUARKUS_PLUGINS/plugins/quarkus-console",
"styled-components": "^6.1.8",
# Edit the packages/app/package.json to add/replace the following dependencies
"@qshift/plugin-quarkus-backend": "link:../../../fork-backstage-quarkus-plugins/plugins/quarkus-backend",
// Yarn install and launch
yarn install
yarn dev
Remark: A side affect of the approach followed here is that some plugin's dependencies should be declared part of the backstage project. Is there an alternative ?
WDYT ? @iocanel
I tested another approach using the workspace option as documented here: https://dev.to/limal/simplify-your-monorepo-with-npm-7-workspaces-5gmj
I then created symbolic links to point to our plugins like this
ln -s /Users/cmoullia/code/openshift/fork-backstage-quarkus-plugins/plugins/quarkus ./plugins/quarkus
ln -s /Users/cmoullia/code/openshift/fork-backstage-quarkus-plugins/plugins/quarkus-console ./plugins/quarkus-console
ln -s /Users/cmoullia/code/openshift/fork-backstage-quarkus-plugins/plugins/quarkus-backend ./plugins/quarkus-backend
and changed too the links of the app and backend
# Edit the packages/app/package.json to add/replace the following dependencies
"@qshift/plugin-quarkus": "link:../../plugins/quarkus",
"@qshift/plugin-quarkus-console": "link:../../plugins/quarkus-console",
# Edit the packages/app/package.json to add/replace the following dependencies
"@qshift/plugin-quarkus-backend": "link:../../plugins//plugins/quarkus-backend",
Unfortunately, we get again the error Dispatcher is not null
as the plugin quarkus (= > QuarkusVersionList) uses a Hook which is loaded using the lib packaged under the plugin node_modules
folder
@iocanel
I experimented the approach documented here : https://github.com/backstage/backstage/blob/master/docs/local-dev/linking-local-packages.md without success
I changed within the root package.json file and lerna.json file the workspaces to be used
},
"workspaces": {
"packages": [
"packages/*",
"plugins/*",
"../fork-backstage-quarkus-plugins/plugins/*"
]
},
and
{
"packages": [
"packages/*",
"plugins/*",
"../fork-backstage-quarkus-plugins/plugins/*"
],
...
Executed again yarn install
and yarn dev
We got when we click on http://localhost:3000/create
the dispatch error BUT this time reported by the plugin-scaffolder-react/
and component: <ScaffolderPageContextMenu>
dispatcher is null
Call Stack
useState
node_modules/@backstage/plugin-scaffolder-react/node_modules/react/cjs/react.development.js:1623:3
ScaffolderPageContextMenu
node_modules/@backstage/plugin-scaffolder-react/dist/alpha.esm.js:1463:82
renderWithHooks
node_modules/react-dom/cjs/react-dom.development.js:16305:27
mountIndeterminateComponent
node_modules/react-dom/cjs/react-dom.development.js:20069:13
beginWork
node_modules/react-dom/cjs/react-dom.development.js:21582:16
callCallback
node_modules/react-dom/cjs/react-dom.development.js:4164:14
invokeGuardedCallbackDev
node_modules/react-dom/cjs/react-dom.development.js:4213:16
invokeGuardedCallback
node_modules/react-dom/cjs/react-dom.development.js:4277:31
beginWork$1
node_modules/react-dom/cjs/react-dom.development.js:27446:28
performUnitOfWork
node_modules/react-dom/cjs/react-dom.development.js:26552:12
Forget my last remark. @iocanel
I created a new backstage app 1.27
, set the workspaces as I commented before, declared our plugins to play with QuarkusVersionList - see screenshot and that works without having to create ln -s
:-)
Note: We will have to bump our backstage-playground to see if the react errors are gone !
The approach works too on our backstage-playground project and react error are gone at the condition that we also first remove the yarn.lock file
// bastage-playground/package.json
"workspaces": {
"packages": [
"../fork-backstage-quarkus-plugins/plugins/*",
"packages/*",
"plugins/*"
]
},
...
rm -rf node_modules
rm yarn.lock
yarn install; yarn dev
I think that I prefer the simplicity of the mono repo, as it allows faster development.
If we continue with the split repo, even if we solve the problem of linking project, we still have drawbacks like:
Conclusion about this ticket:
yarn link/unlink
as it don't at all allow to handle one repository of node modules and will generate React errors as multiple copy of the libs existThe only viable approach to have one node_modules folder is to declare part of the root/parent project the list of the workspaces to be handled by yarn and to define there the path to the plugins project.
TODO
Review instructions to link/unlnk a module/package within the DEVELOPER.md file
Producer of package
Consumer of the package
Notes:
ls -la ~/.config/yarn/link/@qshift
yarn install
See: https://blog.alyssaholland.me/npm-yarn-link