Struggling to set up an express api within a pnpm turborepo workspace.
The api relies on @my/shared as a dependency, which is a local workspace package.
I have been facing challenges in getting the build process right. It seems like I need to build the shared library and integrate it into the api project. However, to accomplish this, I need to modify all import statements to ensure that node can locate the module since it is imported as @my/shared.
Directory structure:
apps/
/api <- express (depends on @my/shared)
packages/
/shared <- @my/shared
Primary tsconfig settings:
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"module": "CommonJS",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"noUncheckedIndexedAccess": true,
"composite": false,
"declaration": true,
"declarationMap": true,
"inlineSources": false,
"outDir": "./dist"
},
"exclude": ["node_modules", "build", "dist", ".next", ".expo"]
}
Configs for express & shared tsconfigs:
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "src",
"paths": {
"~/*": ["*"]
},
"module": "commonjs",
"outdir": "./dist"
},
"include": [
"src",
]
}
My goal is to convert this ts app to js for running in production mode using pm2.
Despite searching through various resources, I have not been able to find a solution.
Attempts include running tsc from the root directory, leading to a 'Error: Cannot find module 'express'' when executing the output with node.
Running tsc at the api level results in an error during pnpm installation in /dist:
ERR_PNPM_WORKSPACE_PKG_NOT_FOUND: @my/shared