The task:
I developed a ShoppingCard project to test TypeScript references.
The issue:
When models are directly included in the main project, the MongoDB connection works successfully.
https://github.com/pzoli/shoppingcard-api
Tested at http://localhost:8080/api-docs/
However, when I move models to a referenced project, I encounter the following error:
MongooseError: Operation amounttypes.find()
buffering timed out after 10000ms
https://github.com/pzoli/shoppingcard-api/tree/ref-models
https://github.com/pzoli/shoppingcard-models
The configuration in tsconfig.json for shoppingcard-api is:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "./build",
"strict": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"references": [{ "path": "../shoppingcard-models" }],
}
The tsconfig.json setup for shoppingcard-models is as follows:
{
"compilerOptions": {
"sourceMap": true,
"target": "esnext",
"module": "CommonJS",
"outDir": "./dist",
"baseUrl": "./src",
"alwaysStrict": true,
"noImplicitAny": true,
"importHelpers": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
"skipLibCheck": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"types": [
"node"
],
"rootDir": "./src",
"typeRoots": [
"node_modules/@types"
],
"composite": true
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"dist"
]
}
Here is the package.json file for shoppingcard-api:
{
"name": "quizserver",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node build/app.js",
"build": "tsc",
"dev": "nodemon"
},
"nodemonConfig": {
"watch": [
"src"
],
"ext": "ts",
"exec": "ts-node src/app.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.0.3",
"express": "^4.18.2",
"joi": "^17.9.1",
"mongoose": "^7.0.4",
"swagger-ui-express": "^4.6.2",
"typescript": "^5.0.4",
"yaml": "^2.2.1"
},
"devDependencies": {
"@types/express": "^4.17.17",
"@types/joi": "^17.2.3",
"@types/node": "^18.15.12",
"@types/swagger-ui-express": "^4.1.3",
"nodemon": "^2.0.22",
"ts-node": "^10.9.1"
}
}
And here is the package.json content for shoppingcard-models:
{
"name": "backend-models",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc"
},
"author": "",
"license": "ISC",
"dependencies": {
"joi": "^17.9.2",
"mongoose": "^7.2.2",
"tslib": "^2.5.3"
}
}
Your assistance in finding the reason why Mongoose is not working is greatly appreciated.