I'm getting the following error when I try to import mongoose with TypeScript
node_modules/mongoose/node_modules/mongodb/mongodb.d.ts:3309:5 - error TS2416: Property 'end' in type 'GridFSBucketWriteStream' is not assignable to the same property in base type 'Writable'.
Apparently this was fixed in mongodb 4.3.0, but mongoose uses mongodb 4.2.2
How could I force mongoose to use mongodb 4.3.0+ ?
I tried adding
"overrides": {
"mongoose": {
"mongodb": "^4.3.0"
}
},
to package.json but it didn't fix the issue.
Here's my package.json
{
"name": "reports",
"version": "1.0.0",
"type": "module",
"description": "",
"main": "index.js",
"engines": {
"node": "16.x"
},
"jest": {
"setupFiles": [
"<rootDir>/jestTestEnv.js"
]
},
"scripts": {
"test": "jest --watchAll --setupFiles ./jestTestEnv.js",
"dev": "tsc && nodemon -r dotenv/config dist/server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.1",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-jwt": "^6.1.0",
"express-openid-connect": "^2.5.2",
"express-validator": "^6.14.0",
"jwks-rsa": "^2.0.5",
"mongoose": "^6.1.1"
},
"overrides": {
"mongoose": {
"mongodb": "^4.3.0"
}
},
"devDependencies": {
"#types/body-parser": "^1.19.2",
"#types/cors": "^2.8.12",
"#types/express": "^4.17.13",
"#types/express-jwt": "^6.0.4",
"#types/jest": "^27.4.0",
"#types/node": "^17.0.13",
"#types/supertest": "^2.0.11",
"jest": "^27.4.5",
"supertest": "^6.1.6",
"typescript": "^4.5.5"
}
}
Found the solution. There seems to be a bug here with NPM. Deleting both node_modules AND package-lock.json and then doing npm install fixes the issue. Deleting node_modules on its own doesn't fix it.
Related
Whenever I'm trying to install koa yarn add apollo-server-koa graphql, I'm getting this error:
Couldn't find package "#koa/cors#^2.2.1" required by "apollo-server-koa" on the "npm" registry.
I tried npm instead of yarn and I got the same error.
Here is my package.json file:
"name": "onlineshopbe",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"bcrypt": "^5.0.0",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-handlebars": "^5.1.0",
"file-url": "^3.0.0",
"graphql": "^15.3.0",
"graphql-relay": "^0.6.0",
"graphql-sequelize": "^9.4.0",
"jsonwebtoken": "^8.5.1",
"koa": "^2.13.0",
"multer": "^1.4.2",
"nodemon": "^2.0.4",
"pg": "^8.3.0",
"sequelize": "^6.3.4"
},
"devDependencies": {},
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
},
"author": "",
"license": "ISC"
}
Any suggestions please?
To clarify the issue:
I have built a node server, which works fine. But on pushing to git and cloning elsewhere, it doesn't work in the new location.
Cleared node_modules, and tried npm install.
gitignore has only node_modules directory in it.
package.json contains the following
{
"name": "node-todo-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node server/server.js",
"test": "export NODE_ENV=test || SET NODE_ENV=test && mocha server/**/*.test.js",
"test-watch": "nodemon --exec 'npm test'"
},
"engines": {
"node": "6.2.2"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.15.2",
"express": "^4.14.0",
"jsonwebtoken": "^8.3.0",
"lodash": "^4.15.0",
"mongodb": "^2.2.5",
"mongoose": "^4.5.9",
"validator": "^5.6.0"
},
"devDependencies": {
"expect": "^1.20.2",
"mocha": "^5.2.0",
"nodemon": "^1.10.2",
"supertest": "^3.1.0"
}
}
I am running tsc --watch (compiling typescript into javascript) and catching warning:
router/PostRouter.ts(103,16): error TS2503: Cannot find namespace 'postRoutes'.
In my .ts file in the 103 string:
const postRoutes = new PostRouter();
postRoutes.routes();
export default postRoutes.router;
So, what's wrong?
My package.json file:
{
"name": "typescript-express-server",
"version": "1.0.0",
"main": "./build/index.js",
"license": "MIT",
"scripts": {
"start:server": "nodemon --watch ./build/index.js",
"watch:build": "tsc --watch"
},
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "1.18.2",
"compression": "1.7.2",
"cookie-parser": "1.4.3",
"cors": "2.8.4",
"dotenv": "5.0.1",
"express": "4.16.3",
"helmet": "3.12.0",
"lodash": "4.17.5",
"mongoose": "5.0.15",
"morgan": "1.9.0"
},
"devDependencies": {
"#types/body-parser": "1.16.8",
"#types/cookie-parser": "1.4.1",
"#types/cors": "2.8.4",
"#types/express": "4.11.1",
"#types/mongoose": "4.7.32",
"#types/node": "9.6.6",
"nodemon": "1.17.3",
"tslint": "5.9.1",
"typescript": "2.8.3"
}
}
Do
const { router } = postRoutes
export default router
in export default postRoutes.router, TS assumes that postRoutes is a namespace.
I need some help, i'm trying to add mongoose to my openshift v3 env but can't find how.
already try to use package.json.
Edit :
deploy log
package.json
{
"name": "nodejs-ex",
"version": "0.0.1",
"description": "projet",
"main": "server.js",
"dependencies": {
"body-parser": "^1.17.2",
"chai": "^3.5.0",
"chai-http": "^2.0.1",
"ejs": "^2.4.1",
"express": "^4.13.4",
"mocha": "^2.4.5",
"mongodb": "^2.1.16",
"mongoose": "^4.10.3",
"morgan": "^1.7.0",
"object-assign": "4.1.0"
},
"engine": {
"node": "*",
"npm": "*"
},
"scripts": {
"start": "node server.js",
"test": "IP=0.0.0.0 PORT=3030 mocha --timeout 5000 tests/*_test.js"
},
Thanks
package.json:
{
"name": "flux-pricing",
"version": "0.0.1",
"description": "Pricing component with flux",
"main": "js/app.js",
"dependencies": {
"flux": "^2.0.0",
"jest-cli": "^0.5.0",
"jsdom": ">= 0.1.23 < 4.0.0",
"react": "^0.12.0",
"underscore": "^1.7.0"
},
"devDependencies": {
"browserify": "~6.2.0",
"envify": "~3.0.0",
"react": "^0.12.0",
"reactify": "^0.15",
"watchify": "~2.1.0",
"gulp": "~3.8.9",
"gulp-browserify": "~0.5.0",
"gulp-concat": "~2.4.1",
"node-jsx": "~0.2.0",
"express": "~4.0.0"
},
"scripts": {
"start": "watchify -o js/bundle.js -v -d .",
"build": "browserify . | uglifyjs -cm > js/bundle.min.js",
"test": "jest"
},
"jest": {
"rootDir": "./js"
},
"browserify": {
"transform": [
"reactify",
"envify"
]
}
}
after npm install when i try to do npm test
s\jsdom\lib\jsdom.js:3
`jsdom 4.x onward only works on io.js, not Node.jsT: https://github.com/tmpvar
^
Unexpected token ILLEGAL
how to resolve this issue?
I had the same problem. The solution is to switch to use Jest 0.4 instead.
Here's the issue from github.
https://github.com/facebook/jest/issues/469#issuecomment-133105627
I actually had to downgrade to Jest 0.3 and node 10.x to get the Jest React example working. Here's the reference
https://github.com/facebook/jest/issues/427