'How do I load a package from a package in a Lerna monorepo?
I have:
packages
-models
-package.json
-....
-server
-src
-index.ts
-package.json
In my packages/server/package.json, I have:
"scripts": {
"dev": "ts-node src/index.ts"
},
"dependencies": {
"@myapp/models": "../models",
In my packages/server/src/index.ts, I have:
import { sequelize } from '@myapp/models'
In my packages/models/src/index.ts, I have:
export type UserAttributes = userAttr
export { sequelize } from './sequelize';
but it gives me an error:
Try `npm install @types/myapp__models` if it exists or add a new declaration (.d.ts) file containing `declare module '@myapp/models';`
import { sequelize } from '@myapp/models'
How do I get this to work properly?
Solution 1:[1]
I don't know Lerna, but a good tool to deal with monorepos is npm link.
- cd packages/models
- npm link
- cd packages/server
- restore the version in dependencies
"@myapp/models": "x.y.z", - npm link @myapp/models
It should be enough.
Hope this helps.
Solution 2:[2]
lerna bootstrap first then yarn add <package_name> works Or lerna bootstrap first, then add the package and the target version then run yarn.
Solution 3:[3]
After you put in the dependencies in your server's package.json, you just need to run
lerna run --stream build
And your local should be able to access to it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | iamonuwa |
| Solution 3 | R.R |
