You may need an appropriate loader to handle this file type.

    最近在构建一个typescript+react简单项目的时候遇到了一个问题,运行webpack命令的时候报错You may need an appropriate loader to handle this file type.可是我明明安装了ts的loaderreact

module.exports = {
    entry: "./src/index.tsx",
    output: {
        filename: "bundle.js",
        path: __dirname + "/dist"
    },
    // Enable sourcemaps for debugging webpack's output.
    devtool: "source-map",
    resolve: {
        // Add '.ts' and '.tsx' as resolvable extensions.
        extensions: [".ts", ".tsx", ".js", ".json"]
    },
    module: {
        rules: [
            // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
            { test: /\.tsx?$/, loader: "awesome-typescript-loader" },
            // { test: /\.tsx?$/, loader: "ts-loader" },
            // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
            { enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
        ]
    },
    externals: {
        "react": "React",
        "react-dom": "ReactDOM"
    }
}

后来发现,当时项目搭建的时候官网让我安装webpack的时候我没有安装,用的全局webpack,项目中未安装,因此我又安装了webpack和webpack-cli,而后就解决了上述问题。webpack