My project structure is like this
project/
packages/
common/
src/
*.ts
package.json
tsconfig.json
main/
src/
main.ts
package.json
tsconfig.json
package.json
tsconfig.json
project/tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"baseUrl": ".",
"paths": {
"@project/comon": [
"packages/common/dist"
]
},
"module": "Node16",
"moduleResolution": "Node16",
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
project/packages/some-module/tsconfig.json / project/packages/main/tsconfig.json (same)
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
}
}
project/package.json
{
"name": "project",
"version": "1.0.0",
"description": "some description",
"private": true,
"workspaces": [
"packages/common",
"packages/describe"
],
"author": "L.S.",
"license": "MIT",
"scripts": {
"build": "yarn workspaces run -Apt build"
}
}
project/packages/common/package.json
{
"name": "@project/common",
"version": "1.0.0",
"description": "some description",
"type": "module",
"author": "L.S.",
"license": "MIT",
"scripts": {
"build": "tsc"
},
"devDependencies": {
"@types/node": "^20.12.11",
"typescript": "^5.4.5"
}
}
project/packages/main/package.json
{
"name": "@project/main",
"version": "1.0.0",
"description": "some description",
"main": "dist/main.js",
"author": "L.S.",
"license": "MIT",
"scripts": {
"build": "tsc",
"start:prod": "node dist/main.js",
"start:dev": "tsnd --watch src --respawn --transpile-only src/main.ts"
},
"dependencies": {
"@project/common": "1.0.0"
},
"devDependencies": {
"@types/node": "^20.12.11",
"ts-node-dev": "^2.0.0",
"typescript": "^5.4.5"
}
}
And now with this setup if I try to import something from @project/common
in project/packages/main/src/main.ts, when I try to compile with tsc, it yells Cannot find module @project/common or its corresponding type declarations.
(and I also checked that @project/common
was build beforehand, so it’s not the problem).