我的ts源文件输出位于root / distr文件夹中。
我的ts测试文件输出与source:root / tests
位于同一文件夹中我有这个目录结构:
root
--- distr
--- fileA.js
--- api
--- myapi.js
--- src
--- fileA.ts
--- api
--- myapi.ts
--- tests
--- unit
--- specs
--- api
--- testA.spec.js
--- testA.spec.ts
testA.spec.ts
内容:
import * as myapi from "api/myapi"; //<= this is where I get the error
describe("API: \"app/version\" route", () => {
it("should return the version", (done) => {
expect(200).toBe(200); //on purpose for now
done();
});
}
tsconfig.json
内容:
"outDir": "../distr",
"baseUrl": ".",
"paths": {
"*": ["src/*"],
"api/*": ["src/api/*"],
},
在gulpfile.js
内容中,我有:
runSequence('clean:tests', 'build:tests', 'jasmine', function() {
done();
});
gulp.task('build:tests', function () {
return gulp.src(['tests/**/*.ts'])
.pipe(ts())
.pipe(gulp.dest('tests/'));
});
gulp.task('jasmine', function(done) {
return gulp.src('tests/**/*.spec.js')
.pipe(plumber(function (error) {
console.log(error.toString());
this.emit('end');
}))
.pipe(jasmine());
})
当我运行gulp命令时,我得到:
[19:44:25] Starting 'build:tests'...
[19:44:28] Finished 'build:tests' after 2.39 s
[19:44:28] Starting 'jasmine'...
BLA:Error in plugin "gulp-jasmine"
Message:
Cannot find module 'api/myapi'
Details:
code: MODULE_NOT_FOUND
知道为什么我收到这条消息? 谢谢!
答案 0 :(得分:0)
尝试:
import EngineA from "./engines/engineA"
(确保本地路径正确)。如果是这样,那么你必须正确配置"baseUrl": and "rootDirs" in
tsconfig.json`。祝好运。