#Local typescript package in a monorepo

10 messages · Page 1 of 1 (latest)

fallen kindle
#

Hello, i'm getting an error while importing my local package in one of the apps in my monorepo

Error: Cannot find module '@acme/lib/clients/FireBaseClient'

the project setup -

@root/
├── apps/
│   └── cdn/
│       ├── ...
│
└── packages/
    └── lib/
        ├── ...

apps/cdn/tsconfig.json

{
  "extends": "@acme/tsconfig/base.json",
  "compilerOptions": {
    "target": "es5",
    "jsx": "preserve",
    "outDir": "dist",
    "resolveJsonModule": true,
  },
  "references": [
    {
      "path": "../../packages/lib"
    }
  ],
  "include": ["."],
  "exclude": ["node_modules", "./dist"]
}

packages/lib/tsconfig.json

{
  "extends": "@acme/tsconfig/base.json",
  "compilerOptions": {
    "lib": ["es2022"],
    "module": "commonjs",
    "target": "es2022",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "outDir": "dist",
    "declaration": true,
    "composite": true
  },
  "include": [".", "./config/*.json"],
  "exclude": ["dist", "build", "lib", "node_modules"]
}

packages/lib/package.json

{
  "name": "@acme/lib",
  "version": "1.0.0",
  "private": true,
  "description": "external libs and utilites combined",
  "author": "Oreki",
  "license": "Apache-2.0",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "scripts": {
    "build": "tsc",
    "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
    "lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix"
  },
  "dependencies": {
    "@google-cloud/storage": "^7.0.1",
    "firebase-admin": "^11.10.1",
    "lodash": "^4.17.21"
  },
  "devDependencies": {
    "@acme/eslint": "workspace:^",
    "@acme/prettier": "workspace:^",
    "@acme/tsconfig": "workspace:^",
    "@types/lodash": "^4.14.198",
    "@types/node": "20.5.1",
    "typescript": "5.1.6"
  }
}

what could i be doing wrong

fallen kindle
#

but if i import it like this after building the lib package

import FireBaseClient from '@miyabi/lib/dist/clients/FireBaseClient';

it works without any errors

sturdy skiff
#

Is this when you're using something like ts-node or an intermediate tool? Because this will look for the entry point in the main location you set up which is dist/index.js, whereas I believe the your actual code is in a different location

fallen kindle
#

Nope I'm not using ts-node or anything, and about my code location, it's in packages/lib/index.ts
packages/lib/capitalise.ts
And so on single ts files

sturdy skiff
#

So what command are you running when you get the error?

fallen kindle
#

pnpm run start on apps/cdn, I get the error that it can't find the module I'm trying to import from packages/lib

sturdy skiff
#

There is no start on any of the packages you've included

fallen kindle
#

Well the local package would ofcourse not have a start script, but I'm talking that I'm running the start script in the app called cdn and not in the package called lib

sturdy skiff
#

I'm trying to get an understanding of the whole system, without it I can't help you debug your problem. All I need to know at this point is what is the contents of that start script

fallen kindle
#

node dist/index.js