【发布时间】:2016-01-23 09:13:55
【问题描述】:
所以我有一个看起来像这样的项目:
应用程序/ 仓/ 库/ 源/ 主要的/ 子模块.ts 公用事业/ common.ts main.ts tsconfig.json gulpfile.js而app/src/main/submodule.ts 需要导入app/src/utilities/common.ts。我正在尝试为此使用 ES6 语法。因此,我希望在submodule.ts 中有这样的内容:
import {common} from '/utilities/common';
根/ 是app/src/,因为这是找到tsconfig 的位置。是的,app/src/utilities/common.ts 确实导出了一个名为 common 的模块。
问题是我收到“找不到模块'/utilities/common'”错误。我尝试了很多方法:
utilities/common/src/utilities/common/app/src/utilities/common
这些都不起作用。 ../utilities/common 的相对路径确实有效,但常见模块的相对路径是维护的噩梦。
值得注意的是,我刚刚从 TS 1.5 更新到 1.6:使用 utilities/common 已经在 1.5 中工作。不过,我在 1.6 的注释中找不到任何关于这些方面的重大更改。
我提到gulpfile.ts 和其他文件夹,因为最终我希望Gulp 从src 获取TS 文件并将编译好的JS 文件放在bin 中。我有理由相信我已经正确配置了 Gulp,使用 gulp-typescript,但为了完整起见,这里是我的 tsconfig.json 和 gulpfile.js。
-
{ “编译器选项”:{ “模块”:“commonjs”, “目标”:“es5”, “experimentalDecorators”:是的, “emitDecoratorMetadata”:真, “noEmitOnError”:真 }, “文件全球”:[ "./**/*.ts", “!./typings/**/*.ts” ] }tsconfig.json -
var gulp = require('gulp'); var ts = require('gulp-typescript'); var less = require('gulp-less'); var sourcemaps = require('gulp-sourcemaps'); var 合并 = 要求('merge2'); var path = require('path'); var tsProject = ts.createProject('src/tsconfig.json', { noExternalResolve: true }); gulp.task('html', function () { 吞咽.src([ 'src/**/*.html', ]) .pipe(gulp.dest('bin')); }); gulp.task('typescript', function () { tsProject.src() .pipe(sourcemaps.init()) .pipe(ts(tsProject)) .js .pipe(sourcemaps.write()) .pipe(gulp.dest('bin')); }); gulp.task('less', function () { 吞咽.src([ 'src/**/*.less', ]) .pipe(sourcemaps.init()) .pipe(少()) .pipe(sourcemaps.write()) .pipe(gulp.dest('bin')) }); gulp.task('default', ['html', 'typescript', 'less']);gulpfile.js
【问题讨论】:
标签: import typescript