我的ts源文件输出在root/distr文件夹中。
我的ts测试文件输出与源文件位于同一个文件夹中: root/tests
我有这样的目录结构:
root
--- distr
--- fileA.js
--- api
--- myapi.js
--- src
--- fileA.ts
--- api
--- myapi.ts
--- tests
--- unit
--- specs
--- api
--- testA.spec.js
--- testA.spec.tstestA.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知道我为什么收到这条消息吗?谢谢!
发布于 2018-05-13 02:37:45
尝试:
import EngineA from "./engines/engineA"
(确保本地路径正确)。如果是这样,那么您必须正确配置"baseUrl": and "rootDirs" intsconfig.json`。祝好运。
https://stackoverflow.com/questions/50308227
复制相似问题