Reputation: 81
I've been working on a PoC monorepo for a designsystem where I've tried to render components to sketch using react primitives + react sketchapp. I'm using Lerna in combination with yarn workspaces for managing dependecies for the different packages which means the folder structure looks like this:
my-repo/
package.json
lerna.json
tsconfig.json
(...)
node_modules
packages/
react-sketchapp-package/
package.json
(...)
web-components-package/
package.json
(...)
After facing problems with having the same dependency (styled-components) in both packages I switched to use lerna in combination with yarn workspaces. Which means that you have node_modules in the root of the monorepo instead of in the packages. It solved my problems i had before with styled components, and it works like a charm in the web-components-repo, but when trying to run any script in the react-sketchapp-repo i get the following error:
src/Document.tsx(50,46): error TS2304: Cannot find name 'context'. npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! @[email protected] typescript:once:
tsc
npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the @[email protected] typescript:once script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install?
It seems as if the react-sketchapp package does not find the node_modules dependencies after switching to Yarn workspaces. I tried to create a symlink in the react-sketchapp-package to node_modules using:
ln -s ../../node_modules ./node_modules
But that didn't work either, still the same problem...
Since this is my first experience with Lerna and workspaces i'm going to retrace my steps and see if theres any configuration I've missed but if any one have any ideas how to solve this it would be really appreciated!
Upvotes: 1
Views: 510
Reputation: 81
Update: 1 month later
one mayor problem with my repo was that i had forgot to add "packages":["packages/*"]
to my lerna.json in root. It might be some other configuration missing aswell, but when i migrated my sketchapp-repo to another monorepo, with workspace configured the right way the problems went away. I also had some problems with conflicting dependencies. It might be good to take a look in this repo to understand what dependencies you need for a basic setup:
https://github.com/airbnb/react-sketchapp/blob/master/examples/basic-setup-typescript/package.json
Upvotes: 0