我下载了 Typescript、Express、Sequelize、Postgres 示例并运行npm install
和npm start
.
npm start
它正在产生一些错误。
[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
包.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(错误相关部分)
...
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"
]
}
我看到这篇这篇文章是为了解决这个问题,但在tsconfig.json"files"
的属性中包含什么是没有意义的。
我该如何解决这个错误?有没有人遇到过这种错误?
感谢您提供任何帮助。