Build typescript/express application - node.js

The application functions smoothly during the development phase, however, it encounters difficulties when being built. The issue arises during the build process, causing imports errors in the the app.
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'dependency' imported from C:\Users\adria\root\media-hunters\coffee-reviews\be\dist\index.js
i'm getting errors like this one
package.json
{
"name": "coffee-reviews",
"version": "1.0.0",
"description": "",
"main": "src/index.ts",
"type": "module",
"scripts": {
"build": "tsc -p tsconfig.json",
"serve": "npm run build && node dist/index.js",
"start": "ts-node -r tsconfig-paths/register src/index.ts",
"dev": "npm run db:migrate && nodemon --experimental-modules --es-module-specifier-resolution=node index.ts",
"format": "prettier **/*.ts --write",
"lint": "npx eslint --fix ./**/*.ts",
"db:seed": "ts-node -r tsconfig-paths/register -r dotenv/config node_modules/typeorm-seeding/dist/cli.js seed -n ormconfig.js -c default",
"db:reload": "ts-node src/infrastructure/database/cli/dbReload.ts reload",
"db:migrate": "ts-node -r tsconfig-paths/register node_modules\\typeorm\\cli.js migration:run",
"db:generate": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js migration:generate -n",
"db:packet": "npm run db:reload && npm run db:migrate && npm run db:seed"
},
"lint-staged": {
"src/**/*.ts": [
"prettier --write",
"eslint --fix"
]
},
"dependencies": {
"#types/bcrypt": "^3.0.0",
"#types/cors": "^2.8.6",
"#types/express": "^4.17.13",
"#types/express-serve-static-core": "^4.17.30",
"#types/faker": "^4.1.9",
"#types/helmet": "^0.0.45",
"#types/jsonwebtoken": "^8.3.7",
"#types/method-override": "^0.0.31",
"#types/morgan": "^1.7.37",
"#types/node": "^13.5.0",
"#types/swagger-ui-express": "^4.1.1",
"#types/yargs": "^15.0.1",
"#wufe/mapper": "^0.5.0",
"#zerollup/ts-transform-paths": "^1.7.18",
"apollo-server-express": "^3.11.1",
"bcrypt": "^5.0.0",
"cors": "^2.8.5",
"debug": "~4.1.1",
"dotenv": "^8.2.0",
"express": "~4.17.1",
"graphql": "^15.8.0",
"graphql-tools": "^8.3.14",
"helmet": "^3.21.2",
"http-status-codes": "^1.4.0",
"inversify": "^6.0.1",
"inversify-express-utils": "^6.3.2",
"jsonwebtoken": "^9.0.0",
"method-override": "^3.0.0",
"morgan": "^1.9.1",
"path": "^0.12.7",
"pg": "^8.8.0",
"reflect-metadata": "^0.1.13",
"swagger-ui-express": "^4.1.3",
"ttypescript": "^1.5.15",
"type-graphql": "^1.1.1",
"typeorm": "^0.2.45",
"typeorm-seeding": "^1.6.1",
"typeorm-transactional-cls-hooked": "^0.1.20",
"winston": "^3.2.1",
"winston-daily-rotate-file": "^4.7.1",
"yargs": "^17.6.2"
},
"devDependencies": {
"#types/chai": "^4.2.7",
"#types/sinon": "^7.5.1",
"#typescript-eslint/eslint-plugin": "^5.50.0",
"#typescript-eslint/parser": "^5.48.0",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"eslint": "^8.31.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^6.10.0",
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-typescript-sort-keys": "^2.1.0",
"husky": "^3.1.0",
"lint-staged": "^7.3.0",
"nodemon": "^2.0.2",
"prettier": "^2.8.2",
"ts-node": "^10.9.1",
"tsconfig-paths": "^3.14.1",
"typescript": "^4.4.4"
},
"keywords": [],
"author": "",
"license": "ISC"
}
tsconfig.json
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"core/*": ["src/core/*"],
"dependency/*": ["src/dependency/*"],
"infrastructure/*": ["src/infrastructure/*"],
"ui/*": ["src/ui/*"],
"config/*": ["test/config/*"],
"*": [
"#types/*"
]
}
}
}
tsconfig.base.json
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"target": "ESNext",
"module": "ESNext",
"outDir": "dist",
"strict": true,
"sourceMap": true,
"moduleResolution": "node",
"lib": [
"es5",
"es6",
"dom"
],
"plugins": [
{ "transform": "#zerollup/ts-transform-paths" }
],
"esModuleInterop": true
},
"include": [
"src/**/*.ts",
"tests/**/*.ts"
],
"exclude": [
"node_modules"
]
}
i have tried variety of combinations with commonjs and module version every of them end up quiet same, that the imports stop to work

Related

Not being able to run NestJS application

I don't know what happened but I'm not being able to run a NestJS application locally
What I've tried so far:
deleting node_modules
deleting package-lock.json
npm i --save-dev #types/node
gave up and git cloned the whole application in a different folder (that runs on my colleagues' machines but not mine, they couldn't figure it out either)
I've been losing my mind, any help is appreciated
NPM Version 8.5.4
Node.js Version v16.14.2
tsconfig.json:
{
"compilerOptions": {
"lib": ["es2020"],
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"target": "es2020",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./src/",
"paths": {
"<rootDir>/": ["."]
},
"incremental": true,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"resolveJsonModule": true
}
}
tsconfig.build.json:
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "__mocks__", "dist", "**/*spec.ts"]
}
package.json:
{
"name": "REDACTED",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"check-env": "node -r ts-node/register -r tsconfig-paths/register src/checkEnvs.ts",
"prebuild": "rimraf dist && npm run check-env",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node --max-old-space-size=2500 dist/src/main.js",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest --detectOpenHandles",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:noCov": "jest --watch --collectCoverage=false",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"prisma:create": "npx prisma migrate dev --create-only",
"prisma:run": "npx prisma migrate dev",
"prisma:generate": "npx prisma generate"
},
"dependencies": {
"#elastic/elasticsearch": "7.10",
"#nestjs/bull": "^0.4.2",
"#nestjs/common": "^8.0.0",
"#nestjs/config": "^1.1.0",
"#nestjs/core": "^8.0.0",
"#nestjs/elasticsearch": "^8.0.0",
"#nestjs/event-emitter": "^1.0.0",
"#nestjs/microservices": "^8.1.2",
"#nestjs/mongoose": "^9.0.3",
"#nestjs/platform-express": "^8.4.4",
"#nestjs/schedule": "^1.1.0",
"#ntegral/nestjs-sentry": "^3.0.7",
"#prisma/client": "^3.14.0",
"#sentry/node": "^6.17.3",
"#sentry/types": "^6.17.3",
"amqp-connection-manager": "^3.7.0",
"amqplib": "^0.8.0",
"axios": "^0.24.0",
"bull": "^3.29.3",
"class-validator": "^0.13.2",
"cli-progress": "^3.10.0",
"date-fns": "^2.27.0",
"fast-csv": "^4.3.6",
"lodash": "^4.17.21",
"mongoose": "^6.2.10",
"nestjs-ftp": "^0.1.13",
"nestjs-soap": "^2.0.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"xml-js": "^1.6.11"
},
"devDependencies": {
"#golevelup/ts-jest": "^0.3.2",
"#nestjs/cli": "^8.0.0",
"#nestjs/schematics": "^8.0.0",
"#nestjs/testing": "^8.0.0",
"#types/bull": "^3.15.7",
"#types/cli-progress": "^3.9.2",
"#types/cron": "^1.7.3",
"#types/express": "^4.17.13",
"#types/jest": "^27.0.1",
"#types/lodash": "^4.14.179",
"#types/node": "^16.0.0",
"#types/sax": "^1.2.3",
"#types/supertest": "^2.0.11",
"#types/validator": "^13.7.2",
"#typescript-eslint/eslint-plugin": "^4.28.2",
"#typescript-eslint/parser": "^4.28.2",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^27.0.6",
"leaked-handles": "^5.2.0",
"mongodb-memory-server": "^8.4.2",
"prettier": "^2.3.2",
"prisma": "^3.14.0",
"supertest": "^6.1.3",
"ts-jest": "^27.0.3",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "^3.10.1",
"typescript": "^4.3.5"
}
}
If someone finds this question pulling their hair out, it turned out to have been my tsconfig.json file, all I had to do was roll back the lib version from "lib": ["es2020"] to "lib": ["es2017"],
I wish I had seen that on my crystal ball

ERROR: Error reading "src/core/database/config.ts"

I want to migrate db in Node Nest.JS application.
npx sequelize-cli db:migrate shell command
throws an the below exception:
Exception detail:
Error: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/../src/core/database/config.ts
config.ts File
module.exports = {
development: {
default: {
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME_GLOBAL,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
dialect: process.env.DB_DIALECT,
},
transaction: {
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME_TRANSACTION,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
dialect: process.env.DB_DIALECT,
},
},
test: {
default: {
...
},
transaction: {
...
},
},
staging: {
default: {
...
},
transaction: {
...
},
},
production: {
default: {
...
},
transaction: {
...
},
},
};
.sequelizerc file
const path = require('path');
require('dotenv').config();
module.exports = {
'seeders-path': path.resolve('src/core/database', 'seeders'),
'migrations-path': path.resolve('src/core/database', 'migrations'),
config: path.resolve('src/core/database', 'config.ts'),
};
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"resolveJsonModule": true,
}
}
package.json
{
"name": "name",
"version": "1.0.0",
"description": "des",
"author": "auth",
"repository": {
"type": "git",
"url": "https://....git"
},
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "NODE_ENV=development nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "cp -rv dist/i18n dist/src/ && nest start",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "NODE_ENV=test jest --config ./test/jest-e2e.json",
"db:seed": "npx sequelize-cli db:seed:all",
"db:migrate": "npx sequelize-cli db:migrate",
"testdb:seed": "NODE_ENV=test npx sequelize-cli db:seed:all",
"testdb:migrate": "NODE_ENV=test npx sequelize-cli db:migrate",
"copy-assets": "cp -rv dist/i18n dist/src/"
},
"dependencies": {
"#elastic/ecs-winston-format": "^1.3.1",
"#nestjs-modules/mailer": "^1.6.0",
"#nestjs/axios": "^0.0.5",
"#nestjs/common": "^8.0.0",
"#nestjs/config": "^1.1.0",
"#nestjs/core": "^8.0.0",
"#nestjs/jwt": "^8.0.0",
"#nestjs/passport": "^8.0.1",
"#nestjs/platform-express": "^8.0.0",
"#nestjs/sequelize": "^8.0.0",
"#nestjs/serve-static": "^2.2.2",
"#nestjs/swagger": "^5.1.4",
"#nestjs/throttler": "^2.0.0",
"#sentry/node": "^5.9.0",
"amazon-cognito-identity-js": "^5.2.3",
"aws-sdk": "^2.1048.0",
"bcrypt": "^5.0.1",
"class-transformer": "0.4.0",
"class-validator": "^0.13.1",
"cookie-parser": "^1.4.6",
"dotenv": "^10.0.0",
"elasticsearch": "^16.7.2",
"faker": "^5.5.3",
"firebase": "^9.5.0",
"firebase-admin": "^10.0.0",
"generate-password": "^1.7.0",
"handlebars": "^4.7.7",
"helmet": "^4.6.0",
"json2csv": "^5.0.6",
"jsonwebtoken": "^8.5.1",
"jwk-to-pem": "^2.0.5",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"multer": "^1.4.4",
"nest-winston": "^1.6.2",
"nestjs-i18n": "^8.2.1",
"nestjs-redis": "^1.3.3",
"nestjs-throttler-storage-redis": "^0.1.18",
"nodemailer": "^6.7.2",
"passport": "^0.4.0",
"passport-firebase-jwt": "^1.2.1",
"passport-jwt": "^4.0.0",
"pg": "^8.7.1",
"pg-hstore": "^2.3.4",
"redis": "^4.0.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"sequelize": "^6.11.0",
"sequelize-cli": "^6.3.0",
"sequelize-typescript": "^2.1.1",
"swagger-ui-express": "^4.1.6",
"uuid": "^8.3.2",
"uuidv4": "^6.2.12",
"winston": "^3.3.3"
},
"devDependencies": {
"#nestjs/cli": "^8.0.0",
"#nestjs/schematics": "^8.0.0",
"#nestjs/testing": "^8.0.0",
"#types/cookie-parser": "^1.4.2",
"#types/express": "^4.17.13",
"#types/jest": "^27.0.1",
"#types/lodash": "^4.14.178",
"#types/multer": "^1.4.7",
"#types/node": "^16.0.0",
"#types/nodemailer": "^6.4.4",
"#types/sequelize": "^4.28.10",
"#types/supertest": "^2.0.11",
"#typescript-eslint/eslint-plugin": "^5.0.0",
"#typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.2.5",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "^27.0.3",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "^3.10.1",
"typescript": "^4.3.5"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}

TypeScript alias throws an error in production

I have a Node/Express application with TypeScript but somehow I get an alias error when I try to run the app in Digital Ocean droplet, although everything works fine in my local environment:
/VHF/.npm/_npx/112a5e3dd6e78d88/node_modules/tsc-alias/dist/index.js:60
yield (0, helpers_1.importReplacers)(config, replacers, options.replacers);
^
TypeError: (0 , helpers_1.importReplacers) is not a function
at /VHF/.npm/_npx/112a5e3dd6e78d88/node_modules/tsc-alias/dist/index.js:60:45
at Generator.next (<anonymous>)
at /VHF/.npm/_npx/112a5e3dd6e78d88/node_modules/tsc-alias/dist/index.js:8:71
at new Promise (<anonymous>)
at __awaiter (/VHF/.npm/_npx/112a5e3dd6e78d88/node_modules/tsc-alias/dist/index.js:4:12)
at replaceTscAliasPaths (/VHF/.npm/_npx/112a5e3dd6e78d88/node_modules/tsc-alias/dist/index.js:28:12)
at Object.<anonymous> (/VHF/.npm/_npx/112a5e3dd6e78d88/node_modules/tsc-alias/dist/bin/index.js:17:30)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
This is package.json:
{
"name": "vhf-digital-lending-api",
"version": "1.0.0",
"description": "API for VHF digital lender and payment platform",
"author": "",
"license": "ISC",
"scripts": {
"start": "npm run build&& cross-env; NODE_ENV=production node dist/server.js",
"dev": "cross-env NODE_ENV=development nodemon",
"build": "tsc && npx tsc-alias",
"test": "jest --forceExit --detectOpenHandles",
"lint": "eslint --ignore-path .gitignore --ext .ts src/",
"lint:fix": "npm run lint -- --fix",
"migrate:generate": "ts-node ./node_modules/typeorm/cli.js migration:generate --config src/databases/index.ts -n",
"migration:run": "ts-node --transpile-only ./node_modules/typeorm/cli.js migration:run --config src/databases/index.ts",
"migration:revert": "ts-node --transpile-only ./node_modules/typeorm/cli.js migration:revert --config src/databases/index.ts"
},
"dependencies": {
"#types/cookie-session": "^2.0.44",
"#types/express-session": "^1.17.0",
"agenda": "^4.2.1",
"bcrypt": "^5.0.1",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"compression": "^1.7.4",
"config": "^3.3.6",
"cookie-parser": "^1.4.5",
"cookie-session": "^2.0.0",
"cors": "^2.8.5",
"cross-env": "^7.0.3",
"date-fns": "^2.24.0",
"dotenv": "^9.0.0",
"envalid": "^7.1.0",
"express": "^4.17.1",
"helmet": "^4.6.0",
"hpp": "^0.2.3",
"jest": "^26.6.3",
"joi": "^17.4.2",
"jsonwebtoken": "^8.5.1",
"mkdirp": "^1.0.4",
"morgan": "^1.10.0",
"multer": "^1.4.3",
"node-fetch": "^2.6.6",
"pg": "^8.7.1",
"reflect-metadata": "^0.1.13",
"swagger-jsdoc": "^6.1.0",
"swagger-ui-express": "^4.1.6",
"ts-jest": "^26.5.6",
"ts-node": "^9.1.1",
"typeorm": "^0.2.38",
"typeorm-pagination": "^2.0.3",
"typescript": "^4.4.4",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.4",
"xml2js": "^0.4.23"
},
"devDependencies": {
"#types/bcrypt": "^3.0.1",
"#types/compression": "^1.7.2",
"#types/config": "0.0.38",
"#types/cookie-parser": "^1.4.2",
"#types/cors": "^2.8.12",
"#types/dotenv": "^8.2.0",
"#types/express": "^4.17.13",
"#types/helmet": "^4.0.0",
"#types/hpp": "^0.2.2",
"#types/jest": "^26.0.24",
"#types/jsonwebtoken": "^8.5.5",
"#types/mongoose": "^5.11.97",
"#types/morgan": "^1.9.3",
"#types/node": "^15.14.9",
"#types/supertest": "^2.0.11",
"#types/swagger-jsdoc": "^6.0.1",
"#types/swagger-ui-express": "^4.1.3",
"#types/winston": "^2.4.4",
"#types/xml2js": "^0.4.9",
"#typescript-eslint/eslint-plugin": "^4.22.1",
"#typescript-eslint/parser": "^4.22.1",
"eslint": "^7.25.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.1",
"husky": "^6.0.0",
"lint-staged": "^10.5.4",
"node-config": "0.0.2",
"node-gyp": "^8.3.0",
"nodemon": "^2.0.14",
"prettier": "^2.4.1",
"supertest": "^6.1.6",
"tsconfig-paths": "^3.11.0"
}
}
and this is my tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"target": "es2017",
"lib": ["es2017", "esnext.asynciterable"],
"typeRoots": ["node_modules/#types"],
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"module": "commonjs",
"pretty": true,
"sourceMap": true,
"declaration": true,
"outDir": "./dist",
"allowJs": true,
"noEmit": false,
"esModuleInterop": true,
"resolveJsonModule": true,
"importHelpers": true,
"baseUrl": "src",
"paths": {
// "#/*": ["*"],
// "#controllers/*": ["controllers/*"],
// "#databases": ["databases"],
// "#dtos/*": ["dtos/*"],
// "#entity/*": ["entity/*"],
// "#exceptions/*": ["exceptions/*"],
// "#interfaces/*": ["interfaces/*"],
// "#middlewares/*": ["middlewares/*"],
// "#routes/*": ["routes/*"],
// "#services/*": ["services/*"],
// "#utils/*": ["utils/*"]
}
},
"include": ["src/**/*.ts", "src/**/*.json", ".env"],
"exclude": ["node_modules"]
}
I tried commenting out the aliases but it doesn't seem to work.

error TS5014: Failed to parse file '': Unexpected token u in JSON at position 0. The terminal process terminated with exit code: 1

I am receiving this error.
error TS5014: Failed to parse file '/Users/Documents/tsconfig.json/tsconfig.json': Unexpected token u in JSON at position 0.
The terminal process terminated with exit code: 1
My system setup:
Visual Studio Code Version 1.14.1
Angular 2
node Version v8.0.0
tsc Version 2.4.1
package.json is as follows
{
"name": "angular-quickstart",
"version": "1.0.0",
"description": "QuickStart package.json from the documentation, supplemented with testing support",
"scripts": {
"start": "concurrently \"npm run tsc:w\" \"npm run lite\" ",
"e2e": "tsc && concurrently \"http-server -s\" \"protractor protractor.config.js\" --kill-others --success first",
"lint": "tslint ./app/**/*.ts -t verbose",
"lite": "lite-server",
"pree2e": "webdriver-manager update",
"test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"",
"test-once": "tsc && karma start karma.conf.js --single-run",
"tsc": "tsc",
"tsc:w": "tsc -w"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"#angular/common": "^2.4.10",
"#angular/compiler": "^2.4.10",
"#angular/core": "^2.4.10",
"#angular/forms": "^2.4.10",
"#angular/http": "^2.4.10",
"#angular/platform-browser": "^2.4.10",
"#angular/platform-browser-dynamic": "^2.4.10",
"#angular/router": "^3.4.10",
"angular-in-memory-web-api": "^0.2.5",
"core-js": "^2.4.1",
"rxjs": "^5.4.2",
"systemjs": "^0.19.47",
"zone.js": "^0.7.8"
},
"devDependencies": {
"#types/jasmine": "^2.5.41",
"#types/node": "^6.0.46",
"canonical-path": "0.0.2",
"concurrently": "^3.5.0",
"http-server": "^0.9.0",
"jasmine-core": "~2.4.1",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"lite-server": "^2.3.0",
"lodash": "^4.16.4",
"protractor": "~4.0.14",
"rimraf": "^2.5.4",
"tslint": "^3.15.1",
"typescript": "2.1.6"
},
"repository": {}
}
tsconfig.json is as follows
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"outDir": "dist"
}
}
How did you define your tasks.json? I encountered the same issue when I defined my tasks.json with default typescript type. Following changes in tasks.json worked for me based on the answer in link
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "compile",
"type": "shell",
"command": "tsc -p tsconfig.json",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}

While executing mocha tests, Getting error "reflect-metadata shim is required when using class decorators"

Written one mocha test case with chai in Typescript and followed the article http://brianflove.com/2016/11/11/typescript-2-express-mongoose-mocha-chai/ to install all dependencies.
While I am running the test cases with "npm test", I am getting below error
C:\J\MEAN\MSDN-App\node_modules\#angular\core\bundles\core.umd.js:335
throw 'reflect-metadata shim is required when using class decorators';
^
reflect-metadata shim is required when using class decorators
npm ERR! Test failed. See above for more details.
The package.json is:
{
"name": "test-app",
"version": "1.0.0",
"description": "test description",
"main": "server.js",
"scripts": {
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
"test": "mocha -r ts-node/register test/**/*.ts",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"author": "",
"license": "ISC",
"dependencies": {
"#angular/common": "^2.0.1",
"#angular/compiler": "^2.0.1",
"#angular/core": "^2.0.1",
"#angular/forms": "^2.0.1",
"#angular/http": "^2.0.1",
"#angular/platform-browser": "^2.0.1",
"#angular/platform-browser-dynamic": "^2.0.1",
"#angular/router": "^3.4.10",
"#angular/upgrade": "^2.0.1",
"#covalent/core": "^1.0.0-beta.3-2",
"#ngrx/store": "^2.0.1",
"#types/node": "7.0.7",
"#types/underscore": "^1.8.0",
"angular-in-memory-web-api": "^0.1.1",
"body-parser": "^1.17.1",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"ejs": "^2.5.6",
"express": "^4.15.2",
"mongojs": "^2.4.0",
"node-sspi": "^0.1.14",
"nodemailer": "^4.0.1",
"nodemailer-smtp-transport": "^2.7.4",
"properties-reader": "0.0.15",
"reflect-metadata": "^0.1.10",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.39",
"ts-node": "^3.0.4",
"underscore": "^1.8.3",
"zone.js": "^0.6.25"
},
"devDependencies": {
"#types/chai": "^3.5.2",
"#types/core-js": "0.9.35",
"#types/mocha": "^2.2.41",
"chai": "^3.5.0",
"concurrently": "^3.0.0",
"lite-server": "^2.2.2",
"mocha": "^3.4.1",
"reflect-metadata": "^0.1.10",
"ts-node": "^3.0.4",
"typescript": "^2.0.3",
"typings": "^1.4.0"
}
}
And tsconfig.json is:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"node_modules/#types",
"bower_components",
"typings"
]
}
Please help to resolve the error.
Very simple answer but hard to find out. Should not include the #angular/http in test.ts files and to test services use unit testing, to test angular components we must test with Angular testing utilities.

Resources