I have many apps consuming many libraries in a monorepo, and everything works except the $ sls package
command.
It breaks because it can’t resolve the imports I define in tsconfig
’s.
This is my structure:
- tsconfig.base.json
- apps
- serverless
- tsconfig.json
- app2
- tsconfig.json
- libs
- lib1
- tsconfig.json
- lib2
- tsconfig.json
// tsconfig.base.json
{
"compileOnSave": false,
"compilerOptions": {
"noPropertyAccessFromIndexSignature": false,
"resolveJsonModule": true,
"rootDir": ".",
"esModuleInterop": true,
"sourceMap": true,
"noImplicitReturns": false,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2015",
"module": "esnext",
"lib": ["es2017", "dom"],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"paths": {
"~/*": ["./*"],
"@nx/lib1": ["../../../libs/lib1/src/index.ts"],
"@nx/lib2": ["../../../libs/lib2/src/index.ts"]
},
"types": ["node", "jest"]
},
"exclude": ["node_modules", "tmp"]
}
// apps/serverless/tsconfig.json
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "src"
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
// apps/serverless/tsconfig.app.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["node"]
},
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"],
"include": ["**/*.ts"]
}
like I said everything works, except $ sls package
which produces many errors like:
✘ [ERROR] Could not resolve "@nx/constants"
You can mark the path "@nx/constants" as external to exclude it from the bundle, which will remove this error.
any ideas what I’m missing here?