我正在尝试使用类验证器 https://github.com/pleerock/class-validatorTypescript 项目中的模块。但是,当我编译打字稿时,会发出以下警告:
src/main/ts/domain/Order.ts(1,48): error TS2307: Cannot find module 'class-validator'.
它抱怨的行看起来像这样:
import { IsInt, IsNotEmpty, IsDate, Min } from "class-validator";
我有这样的 gulp 设置:
var gulp = require('gulp');
var ts = require('gulp-typescript');
var tsProject = ts.createProject("tsconfig.json");
gulp.task('default', function() {
return tsProject.src()
.pipe(tsProject())
.js.pipe(gulp.dest("target/main/js"));
});
我的 tsconfig.json 看起来像这样:
{
"files": [
"src/main/ts/**/*.ts"
],
"compilerOptions": {
"experimentalDecorators": true,
"noImplicitAny": true,
"target": "es6"
}
}
想法?
Set "moduleResolution": "node"
在你的tsconfig.json
:
{
"compilerOptions": {
"experimentalDecorators": true,
"moduleResolution": "node",
"noImplicitAny": true,
"target": "es6"
}
}
您可以在此处找到有关 TypeScript 如何解析导入模块的更多信息:https://www.typescriptlang.org/docs/handbook/module-resolution.html#node https://www.typescriptlang.org/docs/handbook/module-resolution.html#node
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)