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.
Related
How do you get round this error in webpack?
Answers in similar threads are poorly explained.
I get this error when trying to run the code and have no idea how to solve it - what steps to take, where to look for error etc.
babel.config.js
module.exports = {
presets: [
[
'#babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
};
webpack.config.js
const path = require('path');
module.exports = {
target: 'node',
output: {
path: path.join(__dirname, './.webpack'),
filename: 'handler.js',
libraryTarget: 'commonjs',
}
};
package.json
{
"name": "rate-repository-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node -r esm ./src/index.js",
"start:dev": "nodemon -r esm ./src/index.js",
"bundle": "cpx src/**/* functions/bundle",
"start:lambda": "netlify-lambda serve ./src/lambda",
"lint": "eslint ./src",
"test": "jest .",
"migrate:make": "knex migrate:make",
"migrate:latest": "knex migrate:latest",
"build": "npm run migrate:latest",
"seed:make": "knex seed:make",
"seed:run": "knex seed:run"
},
"lint-staged": {
"src/**/*.js": "eslint",
"*.{js,json,css,md}": "prettier --write"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/Kaltsoon/rate-repository-api.git"
},
"author": "Kalle Ilves",
"license": "MIT",
"bugs": {
"url": "https://github.com/Kaltsoon/rate-repository-api/issues"
},
"homepage": "https://github.com/Kaltsoon/rate-repository-api#readme",
"dependencies": {
"#apollo/server": "^4.3.0",
"#as-integrations/aws-lambda": "^1.1.0",
"#koa/cors": "^3.0.0",
"apollo-boost": "^0.4.9",
"apollo-server": "^3.3.0",
"apollo-server-core": "^3.3.0",
"apollo-server-koa": "^3.3.0",
"apollo-server-lambda": "^3.11.1",
"axios": "^0.24.0",
"bcrypt": "^5.0.0",
"dataloader": "^2.0.0",
"date-fns": "^2.9.0",
"dotenv": "^11.0.0",
"es6-error": "^4.1.1",
"esm": "^3.2.25",
"graceful-fs": "^4.2.10",
"graphql": "^16.6.0",
"jsonwebtoken": "^8.5.1",
"knex": "^0.95.15",
"koa": "^2.11.0",
"koa-bodyparser": "^4.3.0",
"koa-morgan": "^1.0.1",
"koa-router": "^10.0.0",
"lodash": "^4.17.15",
"lru-cache": "^6.0.0",
"netlify-lambda": "^2.0.15",
"objection": "^3.0.1",
"serverless-plugin-common-excludes": "^4.0.0",
"serverless-plugin-include-dependencies": "^5.0.0",
"sqlite3": "^5.0.2",
"through2": "^4.0.2",
"uuid": "^8.3.2",
"watchman": "^1.0.0",
"winston": "^3.8.2",
"yup": "^0.32.8"
},
"devDependencies": {
"#babel/core": "^7.16.7",
"#babel/eslint-parser": "^7.16.5",
"#babel/preset-env": "^7.8.4",
"cpx": "^1.5.0",
"eslint": "^8.6.0",
"eslint-plugin-jest": "^25.3.4",
"husky": "^4.2.3",
"jest": "^27.4.7",
"lint-staged": "^10.0.7",
"nodemon": "^2.0.7",
"prettier": "^2.2.1",
"serverless-plugin-typescript": "^2.1.4",
"serverless-webpack": "^5.11.0"
},
"type": "commonjs"
}
index.js
import http from 'http';
var fs = require('graceful-fs')
import logger from './utils/logger';
import { API_PORT, APOLLO_PORT } from './config';
import createApolloServer from './apolloServer';
import app from './app';
var gracefulFs = require('graceful-fs')
gracefulFs.gracefulify(fs)
const startServer = async () => {
const httpServer = http.createServer(app);
const apolloServer = createApolloServer();
await apolloServer.listen({ port: APOLLO_PORT });
httpServer.on('request', app.callback());
await new Promise((resolve) =>
httpServer.listen({ port: API_PORT }, resolve),
);
logger.info(`Apollo Server ready at http://localhost:${APOLLO_PORT}`);
};
startServer();
I'm working on node.js project. I have created this project by use Babel which was running fine in previous using node system . i have updated node.js version in my system, after that I'm getting error of Bebel-node. Any one can help me how can i solve this issue??b I have installed all bebal.js module.
I'm using code in bebel.rc
{
"plugins": [
"#babel/plugin-transform-runtime"
],
"presets": [
"#babel/env"
],
"ignore": [
"node_modules",
"src/public"
]
}
this is my updated package.json ....
{
"name": "backend-buluckart-hashing.company",
"version": "0.1.0",
"description": "groffers-nepal",
"main": "index.js",
"scripts": {
"start": "nodemon src/index.js --exec babel-node --presets #babel/env",
"build": "babel src -d dist --source-maps inline --copy-files",
"serve": "node dist/index.js",
"sequelize": "sequelize"
},
"keywords": [],
"author": "Ashutosh singh",
"license": "ISC",
"homepage": "",
"nodemonConfig": {
"ignore": [
"src/public/*"
]
},
"devDependencies": {
"#babel/cli": "^7.17.6",
"#babel/core": "^7.17.5",
"#babel/node": "^7.16.8",
"#babel/plugin-transform-runtime": "^7.17.0",
"#babel/preset-env": "^7.16.11",
"nodemon": "^2.0.15"
},
"dependencies": {
"#babel/runtime": "^7.17.2",
"aws-sdk": "^2.700.0",
"babel-upgrade": "^1.0.1",
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.18.3",
"cookie-parser": "^1.4.3",
"cors": "^2.8.5",
"dateformat": "^3.0.3",
"dotenv": "^8.0.0",
"event-stream": "^4.0.1",
"express": "^4.16.3",
"express-handlebars": "^6.0.2",
"express-sanitizer": "^1.0.5",
"express-session": "^1.15.6",
"helmet": "^3.15.1",
"joi": "^14.3.0",
"joi-date-extensions": "^1.2.0",
"jsonwebtoken": "^8.3.0",
"kue": "^0.11.1",
"mailparser": "^3.4.0",
"moment": "^2.24.0",
"morgan": "^1.9.0",
"multer": "^1.4.1",
"multer-s3": "^2.9.0",
"mysql": "^2.16.0",
"mysql2": "^1.6.4",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"qs": "^6.10.3",
"radis": "^2.0.0",
"razorpay": "^2.0.6",
"react-bootstrap": "^2.1.2",
"read-excel-file": "^5.2.26",
"request": "^2.88.0",
"rotating-file-stream": "^1.4.1",
"sequelize": "^5.21.13",
"sequelize-cli": "^6.4.1",
"speakeasy": "^2.0.0",
"stack-trace": "0.0.10",
"twilio": "^3.72.0"
}
}
"start": "nodemon --exec npx babel-node src/index.js",
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.
Can someone help me regarding this problem. I can run this code by typing npm start but can I run it by any other option like nodemon src/server.js since I want to deploy it to heroku. here is my packag.json
{
"name": "quickstartnodejs",
"version": "1.0.0",
"description": "a quick start for node.js project",
"main": "server.js",
"scripts": {
"start": "nodemon --exec babel-node src/server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/haryphamhust/quickStartNodeJSProject.git"
},
"keywords": [
"nodejs",
"mysql"
],
"author": "Hary Pham",
"license": "ISC",
"bugs": {
"url": "https://github.com/haryphamhust/quickStartNodeJSProject/issues"
},
"engines": {
"node": "14.15.1"
},
"homepage": "https://github.com/haryphamhust/quickStartNodeJSProject#readme",
"dependencies": {
"absorb": "^1.0.1",
"body-parser": "^1.19.0",
"connect-flash": "^0.1.1",
"cookie-parser": "^1.4.5",
"dotenv": "^8.2.0",
"ejs": "^3.1.2",
"express": "^4.17.1",
"express-fileupload": "^1.2.1",
"express-session": "^1.17.2",
"express-validator": "^6.12.0",
"generate-password": "^1.6.0",
"multer": "^1.4.2",
"mysql": "^2.18.1",
"nodemailer": "^6.6.2",
"passport": "^0.4.1",
"passport-local": "^1.0.0"
},
"devDependencies": {
"#babel/core": "^7.14.8",
"#babel/node": "^7.14.7",
"#babel/preset-env": "^7.14.8",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"nodemon": "^2.0.3"
}
}
does anyone have an idea
You could try adding a Procfile. Create a new file in your app root directory and call it Procfile (no dots or extentions). Populate it with the following:
web: node ./src/server.js
Check out the docs here:
https://devcenter.heroku.com/articles/getting-started-with-nodejs
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?