Node.js &引用;找不到模块";错误消息与大口茉莉花

Node.js &引用;找不到模块";错误消息与大口茉莉花,node.js,typescript,tslint,tsconfig,Node.js,Typescript,Tslint,Tsconfig,我的ts源文件输出在根/发行版文件夹中 我的ts测试文件输出与源位于同一文件夹中:root/tests 我有以下目录结构: root --- distr --- fileA.js --- api --- myapi.js --- src --- fileA.ts --- api --- myapi.ts --- tests --- unit --- specs --- api

我的ts源文件输出在根/发行版文件夹中

我的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.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();
    });
}
"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
知道我为什么会收到这个消息吗? 谢谢大家!

试试看:


从“/engines/EngineA”导入EngineA


(确保本地路径正确)。如果是这样,那么您必须在tsconfig.json`中正确配置
“baseUrl”:和“rootDirs”。祝你好运

我配置了tsconfig.ts的paths部分,这样我就不必使用相对路径(类似于“../../../../../src/api/myapi”),当我从src文件夹(而不是tests文件夹)构建ts时,它可以正常工作。我对属性名称的理解是错误的,已修复。如果你只是执行jasmine或tsc而不吞咽会发生什么?比如“npx tsc&&npx茉莉花”?如果那样行得通的话,大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口大口地把。。对不起,没有太多帮助-当事情像这样破裂时,我倾向于简化并进行基本操作…所以我猜您的问题是gulp配置-而不是在tsconfig.json中-您确定要使用gulp吗?我相信你有你的理由,gulp很好,但只使用typescript和ts node depdencies以及这两个npm脚本,你就有运行和观看的经验,我相信比gulp更快:“测试”:“ts node node_模块/jasmine/bin/jasmine”,“观看”:“tsc--watch”,顺便说一句,您不必担心sourcemaps来轻松调试测试,因为您“直接”执行ts代码。我的两分钱,祝你好运