node.jspostgresqltypescriptgulpsequelize-cli

typescript error when compiling node module


I downloaded Typescript, Express, Sequelize, Postgres Example and run npm install and npm start.

On npm start it is producing some errors.

[11:27:11] Starting 'compile:typescript'...
~/node_modules/@types/geojson/index.d.ts(94,54): error TS1005: ',' expected.
~/node_modules/@types/geojson/index.d.ts(104,64): error TS1005: ',' expected.
~/node_modules/@types/handlebars/index.d.ts(22,31): error TS1005: ',' expected.
~/node_modules/@types/handlebars/index.d.ts(24,32): error TS1005: ',' expected.
~/node_modules/@types/handlebars/index.d.ts(99,40): error TS1005: ',' expected.
~/node_modules/@types/express-validator/index.d.ts(23,2): error TS2300: Duplicate identifier 'export='.
~/node_modules/@types/express-validator/index.d.ts(37,28): error TS2374: Duplicate string index signature.
~/node_modules/@types/geojson/index.d.ts(94,56): error TS2368: Type parameter name cannot be 'any'
~/node_modules/@types/geojson/index.d.ts(104,66): error TS2368: Type parameter name cannot be 'any'
~/node_modules/@types/geojson/index.d.ts(106,21): error TS2314: Generic type 'Feature<G, P, any>' requires 3 type argument(s).
~/node_modules/@types/handlebars/index.d.ts(22,33): error TS2368: Type parameter name cannot be 'any'
~/node_modules/@types/handlebars/index.d.ts(22,77): error TS2314: Generic type 'HandlebarsTemplateDelegate<T, any>' requires 2 type argument(s).
~/node_modules/@types/handlebars/index.d.ts(24,34): error TS2368: Type parameter name cannot be 'any'
~/node_modules/@types/handlebars/index.d.ts(24,79): error TS2314: Generic type 'HandlebarsTemplateDelegate<T, any>' requires 2 type argument(s).
~/node_modules/@types/handlebars/index.d.ts(96,15): error TS2314: Generic type 'HandlebarsTemplateDelegate<T, any>' requires 2 type argument(s).
~/node_modules/@types/handlebars/index.d.ts(99,42): error TS2368: Type parameter name cannot be 'any'
~/node_modules/@types/handlebars/index.d.ts(104,22): error TS2314: Generic type 'HandlebarsTemplateDelegate<T, any>' requires 2 type argument(s).
~/node_modules/@types/handlebars/index.d.ts(115,34): error TS2314: Generic type 'HandlebarsTemplateDelegate<T, any>' requires 2 type argument(s).
~/node_modules/express-validator/index.d.ts(24,3): error TS2300: Duplicate identifier 'export='.
src/server.ts(6,35): error TS2497: Module '"express-validator"' resolves to a non-module entity and cannot be imported using this construct.
[11:27:13] TypeScript: 5 syntax errors
[11:27:13] TypeScript: 15 semantic errors

package.json

{
  "main": "build/src/server.js",
  "scripts": {
    "build": "gulp build",
    "doc": "gulp generate:doc",
    "start": "cross-env NODE_ENV=development gulp watch",
    "start:prod": "cross-env NODE_ENV=production gulp watch",
    "run:test": "cross-env NODE_ENV=test gulp test",
    "tslint": "gulp tslint",
    "precommit": "lint-staged",
    "prettify": "tsfmt -r --baseDir ./src",
    "sqlz:migrate": "./node_modules/.bin/sequelize db:migrate",
    "sqlz:undo": "./node_modules/.bin/sequelize db:migrate:undo",
    "sqlz:new": "./node_modules/.bin/sequelize migration:create"
  },
  "lint-staged": {
    "src/**/*.ts": [
      "prettify",
      "git add"
    ]
  },
  "dependencies": {
    "body-parser": "~1.17.0",
    "cors": "~2.8.1",
    "cross-env": "~3.2.3",
    "express": "~4.15.0",
    "express-boom": "~2.0.0",
    "express-validator": "^3.1.3",
    "morgan": "~1.8.1",
    "pg": "~6.1.2",
    "pg-hstore": "~2.3.2",
    "sequelize": "~3.30.2",
    "uuid": "~3.0.1",
    "winston": "~2.3.1"
  },
  "devDependencies": {
    "@types/body-parser": "~0.0.33",
    "@types/chai": "~3.4.35",
    "@types/express": "~4.0.35",
    "@types/express-validator": "~2.20.33",
    "@types/mocha": "~2.2.39",
    "@types/morgan": "~1.7.32",
    "@types/sequelize": "~3.4.40",
    "@types/winston": "~2.2.0",
    "chai": "~3.5.0",
    "extendify": "~1.0.0",
    "glob": "~7.1.1",
    "gulp": "~3.9.1",
    "gulp-istanbul": "~1.1.1",
    "gulp-json-refs": "~0.1.1",
    "gulp-mocha": "~3.0.1",
    "gulp-nodemon": "~2.2.1",
    "gulp-plumber": "~1.1.0",
    "gulp-sourcemaps": "~2.4.0",
    "gulp-tslint": "~7.0.1",
    "gulp-typedoc": "~2.0.2",
    "gulp-typescript": "~3.1.4",
    "husky": "^0.13.2",
    "lint-staged": "^3.4.0",
    "remap-istanbul": "~0.8.4",
    "rimraf": "~2.5.4",
    "run-sequence": "~1.2.2",
    "sequelize-cli": "^2.7.0",
    "tslint": "~4.5.1",
    "typedoc": "~0.5.7",
    "typescript": "~2.2.1",
    "typescript-formatter": "^5.1.1"
  },
  "engines": {
    "node": ">=4.0.0"
  },
}

gulpfile.js(Error Related Part)

...
let gulp = require("gulp");
let sourcemaps = require("gulp-sourcemaps");
...
const COMPILE_TYPESCRIPT = "compile:typescript";
const JS_SRC_GLOB = "./build/**/*.js";
const TS_GLOB = [TS_SRC_GLOB];
const tsProject = typescript.createProject("tsconfig.json");
...
gulp.task(COMPILE_TYPESCRIPT, function() {
    return gulp.src(TS_GLOB)
        .pipe(sourcemaps.init())
        .pipe(tsProject())
        .pipe(sourcemaps.write(".", { sourceRoot: "../src" }))
        .pipe(gulp.dest("build"));
});

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "declaration": false,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true
  },
  "exclude": [
    "node_modules"
  ]
}

I saw this This Post to solve this problem and not make sense what to include in "files" attribute of tsconfig.json.
How can I fix this error? Is there anyone who have met this kind of error?
Thank you for any kind of help.


Solution

  • I have deleted all node modules and added one by one that is mentioned in error when run npm start.

    Here's updated node module.

    "dependencies": {
        "body-parser": "^1.17.1",
        "boom": "^7.1.1",
        "cookie-parser": "^1.4.3",
        "cors": "^2.8.4",
        "cross-env": "^5.1.1",
        "express": "^4.15.2",
        "express-boom": "^2.0.0",
        "express-validator": "^4.3.0",
        "gulp": "^3.9.1",
        "gulp-istanbul": "^1.1.2",
        "gulp-mocha": "^4.3.1",
        "gulp-nodemon": "^2.2.1",
        "gulp-plumber": "^1.1.0",
        "gulp-sourcemaps": "^2.6.1",
        "gulp-tslint": "^8.1.2",
        "gulp-typedoc": "^2.1.1",
        "gulp-typescript": "^3.2.3",
        "morgan": "^1.8.1",
        "nodemon": "^1.12.1",
        "pg": "^6.4.1",
        "postgresql": "0.0.1",
        "pug": "^2.0.0-beta11",
        "reflect-metadata": "^0.1.10",
        "remap-istanbul": "^0.9.5",
        "rimraf": "^2.6.2",
        "run-sequence": "^2.2.0",
        "sequelize": "^3.21.0",
        "sequelize-cli": "^3.0.0",
        "sequelize-typescript": "^0.5.0",
        "serve-favicon": "^2.4.1",
        "tslint": "^5.8.0",
        "typedoc": "^0.9.0",
        "typescript": "^2.6.1",
        "uuid": "^3.1.0",
        "winston": "^2.4.0"
      },
      "devDependencies": {
        "@types/body-parser": "1.16.1",
        "@types/cookie-parser": "^1.3.30",
        "@types/ejs": "^2.3.33",
        "@types/express": "^4.0.35",
        "@types/morgan": "^1.7.32",
        "@types/node": "^7.0.10",
        "@types/serve-favicon": "^2.2.28"
      }