错误:找不到与typescript到javascript的相对路径相关的模块

时间:2017-06-19 07:35:29

标签: javascript typescript protractor tsconfig

在我们的自动化测试中,我们使用带有Typescript的Protractor。所以我们要避免相对路径。 因此在打字稿中我们使用baseURL和Path来解析编译正常的相对路径。

  "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "declaration": false, 
    "removeComments": false, 
    "noImplicitAny": false, 
    "emitDecoratorMetadata":true,
    "experimentalDecorators": true,
    "outDir": "jsout", 
    "types": ["jasmine", "node"],
    "allowJs": true,
    "baseUrl": ".",
     "paths": {
        "factory/*":["factories/*"]        
    }

import{FactoryRegistry} from 'factory/FactoryRegistry.ts'


However, when we are running our spec file, the run time error is thrown 
 E/launcher - Error: Error: Cannot find module 'factory/FactoryRegistry.ts'

这是因为在JS Spec文件中解析了TS Spec文件中解析的路径。在JS spec文件中,它说的是这样的

var FactoryRegistry_ts_1 = require("factory/FactoryRegistry.ts");

而不是"./../../../factories/FactoryRegistry"

那么我们如何在从TS转换为JS

时解决这个问题

0 个答案:

没有答案