1

I am creating a full-stack monorepo project using lerna.

In one of the sub-project I got Cannot find module '@gepick/database/connect'.

my lerna.json

{
  "packages": ["packages/*", "projects/**"],
  "version": "0.0.0",
  "useWorkspaces": true,
  "npmClient": "yarn"
}

my gepick/database/package.json:

{
  "name": "@gepick/database",
  "version": "1.0.0",
  "devDependencies": {
    "@types/lodash": "^4.14.149",
    "@types/mongoose": "^5.7.11",
    "source-map-loader": "^0.2.4"
  },
  "dependencies": {
    "lodash": "^4.17.15",
    "mongodb-client-encryption": "^1.0.1",
    "mongoose": "^5.9.9"
  }
}

node based subproject package.json

{
  "name": "scripts-api-football",
  "version": "1.0.0",
  "scripts": {
    "start:collectDayMatches:dev": "tsc-watch --onSuccess \"node -r source-map-support/register build/collectDayMatches.js\"",
    "build": "tsc"
  },
  "devDependencies": {
    "@types/lodash": "^4.14.149",
    "source-map-loader": "^0.2.4",
    "source-map-support": "^0.5.19",
    "tsc-watch": "^4.2.3"
  },
  "dependencies": {
    "@gepick/database": "^1.0.0",
    "axios": "^0.19.2",
    "commander": "^5.0.0",
    "lodash": "^4.17.15",
    "nodemon": "^2.0.3"
  }
}

node based subproject tsconfig.json

{
  "compilerOptions": {
    "target": "es2019",
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "dist",
    "strict": true,
    "inlineSourceMap": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "allowJs": false,
    "lib": ["es2016", "esnext.asynciterable", "webworker"],
    "types": ["node"],
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strictPropertyInitialization": false,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "forceConsistentCasingInFileNames": true,
    "baseUrl": "./src",
    "paths": {
      "utils/*": ["./utils/*"]
    }
  },
  "exclude": ["tests", "tasks"]
}

main package.json:

{
  "name": "gepick-lerna",
  "version": "1.0.0",
  "private": true,
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "start:front-web": "lerna run start --scope front-web --stream",
    "bootstrap": "lerna bootstrap",
    "build:scripts:api-football": "lerna run build --scope scripts-api-football --stream",
    "start:scripts:api-football:start:collectDayMatches:dev": "lerna run start:collectDayMatches:dev --stream"
  },
  "dependencies": {
    "lerna": "^3.20.2",
    "typescript": "^3.8.3",
    "webpack": "^4.42.1"
  },
  "workspaces": [
    "projects/**",
    "packages/*"
  ],
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^2.27.0",
    "@typescript-eslint/parser": "^2.27.0",
    "eslint": "^6.8.0",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-react": "^7.19.0",
    "eslint-plugin-react-hooks": "^2.5.1"
  }
}

Also, I tried to add main: "connect.js" to @gepick/datebase package.json file. But looks like @gepick/datebase package don`t have compiled js. Maybe it is issue (tsc not compiles library files) ?

3
  • Does this answer your question? LernaJS Typescript cannot find module Commented Apr 28, 2020 at 6:28
  • see if lerna bootstrap solves ur probem Commented Apr 28, 2020 at 6:40
  • I tried to add main option to package.json. Also, I tried run lerna bootsrap from root folder. But app still don`t find model. But maybe problem is that tsc not compile lerna package at all, and it is the reason why can't find it. Commented Apr 29, 2020 at 4:31

1 Answer 1

1

Problem was that packages were not compiled to js. I changed node to ts-node for run script. Now it works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.