I'm trying to use LernaJS with typescript and I have some problems. When I try to run my package-1 which has package-2 as dependency I get the error:
module.js:549 throw err; ^ Error: Cannot find module 'package-2' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object. (/home/gabriel/Documentos/projetos/nodejs/lerna-t2/packages/package-1/dist/index.js:3:19) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3)
I've followed the following steps:
. ├── lerna.json ├── node_modules ├── package.json ├── package-lock.json └── packages ├── package-1 └── package-2
{ "compilerOptions": { "outDir": "dist", "target": "es5", "module": "commonjs" } }
FILE TREE
My 'package-1' file tree:
. ├── dist │ └── index.js ├── index.ts ├── node_modules │ ├── package-2 -> ../../package-2 │ └── typescript ├── package.json ├── package-lock.json └── tsconfig.json
My 'package-2' file tree:
. ├── dist │ ├── index.js │ └── lib │ └── teste.js ├── index.ts ├── lib │ └── teste.ts ├── package.json ├── package-lock.json └── tsconfig.json
CODE
package-1:
import { Teste } from 'package-2' new Teste().printHello()
package-2:
export class Teste { printHello() { console.log('Hello!') } }
export { Teste } from './lib/teste'
Please ensure you have defined main
in your package.json in (at least project-2). I assume the name field in package.json (for project-2) is project-2
.
Main should link to dist/index.js