找不到模块:错误:无法解析“ ReleaseManagement / Core / RestClient”

时间:2019-05-23 09:41:25

标签: typescript webpack ts-loader vss-web-extension-sdk

我正在尝试将Typescript与Webpack(和React)一起使用,以开发Azure DevOps扩展以总结生成和发布数据。扩展程序开发需要vss-web-extension-sdk程序包才能与Azure DevOps进行交互。

当我运行“ webpack”命令时,它某种程度上无法解析程序包中的ReleaseManagement模块(例如“ ReleaseManagement / Core / Contracts”),而它却可以正确地解析Build模块(例如“ TFS / Build / RestClient”)

  

未找到模块:错误:无法解析“ ReleaseManagement / Core / RestClient”

我感到奇怪的是,如果我使用“ tsc”命令进行构建,就不会有问题。

这是我所做的代码和配置。

tsconfig.json

{
"compilerOptions": {
    "module": "amd",
    "moduleResolution": "node",
    "target": "es5",
    "outDir": "dist",
    "lib": [
        "es5",
        "es6",
        "dom"
    ],
    "importHelpers": true,
    "jsx": "react",
    "noEmitHelpers": true,
    "rootDir": "src/",
    "skipLibCheck": true,
    "types": [
        "vss-web-extension-sdk"
    ],
    "sourceMap": true
},
"include": [
    "src/**/*.ts",
    "src/**/*.tsx"
]

}

webpack.config.js

    const path = require("path");

module.exports = {
    context: __dirname,
    entry: "./" + path.relative(process.cwd(), path.join(__dirname, "src", "index.tsx")),
    output: {
        filename: path.relative(process.cwd(), path.join(__dirname, "index.js")),
        libraryTarget: "amd",
    },
    resolve: {
        extensions: [".ts", ".tsx", ".js", ".json"]
    },

    module: {
        rules: [
            { test: /\.tsx?$/, loader: "ts-loader" },
            { enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
        ]
    },

    externals: [
        {
            react: true,
            "react-dom": true,
        },
        /^TFS\//,
        /^VSS\//,
        /^Favorites\//,
    ]
};

我的主要tsx文件(测试返回和div标签为空。)

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Test } from './Test';

import * as BuildClient from "TFS/Build/RestClient"
import * as RMO_Client from "ReleaseManagement/Core/RestClient";

var rm_client = RMO_Client.getClient();
var build_client =BuildClient.getClient();

ReactDOM.render(<Test />, document.getElementById('extensionFrame'));

0 个答案:

没有答案