4

I have a problem with Webpack. It compiles and tree-shakes correctly, but gives me hundreds of errors, because it for some reason does something with type definitions in node_modules, even though it shouldn't, because no module is required/imported in my entry point.

My webpack.config.js:

const ForkCheckerPlugin = require("awesome-typescript-loader").ForkCheckerPlugin;
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const webpack = require("webpack");

module.exports = {
    entry:
    {
        browser: __dirname + "/source/index.tsx"
    },

    module:
    {
        loaders:
        [
            { test: /(\.ts|\.tsx)$/, loader: "awesome-typescript-loader" },
            { test: /\.css$/, loader: ExtractTextPlugin.extract({ loader: "css-loader?modules" }) },
            { test: /\.png$/, loader: "url-loader" },
            { test: /\.jpg$/, loader: "url-loader" },
            { test: /\.json$/, loader: "json-loader" },
        ]
    },

    plugins:
    [
        new webpack.DefinePlugin({ "process.env": { NODE_ENV: JSON.stringify("production") } }),
        new webpack.optimize.DedupePlugin(),
        new webpack.optimize.UglifyJsPlugin({ compressor: { warnings: false } }),
        new webpack.optimize.CommonsChunkPlugin({ name: "vendor", minChunks: module => /node_modules/.test(module.resource) }),
        new ExtractTextPlugin("browser.css"),
    ],

    output:
    {
        filename: "[name].js",
        chunkFilename: "[name].js",
        path:  __dirname + "/build/browser/"
    }
};

My entrypoint (source/index.tsx) - basically nothing:

console.log("Test");

Errors it gives me (shortened, they're all similar):

ERROR in [default] C:\Users\Tom\VSCodeProjects\personal\webpack-test\node_modules\@types\react-router\lib\match.d.ts:12:15
Module '"C:/Users/Tom/VSCodeProjects/personal/webpack-test/node_modules/history/lib/index"' has no exported member 'History'.

ERROR in [default] C:\Users\Tom\VSCodeProjects\personal\webpack-test\node_modules\@types\react-router\lib\match.d.ts:16:80
Module '"C:/Users/Tom/VSCodeProjects/personal/webpack-test/node_modules/history/lib/index"' has no exported member 'Location'.

ERROR in [default] C:\Users\Tom\VSCodeProjects\personal\webpack-test\node_modules\@types\react-router\lib\useRouterHistory.d.ts:1:9
Module '"C:/Users/Tom/VSCodeProjects/personal/webpack-test/node_modules/history/lib/index"' has no exported member 'History'.

ERROR in [default] C:\Users\Tom\VSCodeProjects\personal\webpack-test\node_modules\@types\react-router\lib\useRouterHistory.d.ts:1:18
Module '"C:/Users/Tom/VSCodeProjects/personal/webpack-test/node_modules/history/lib/index"' has no exported member 'HistoryOptions'.

ERROR in [default] C:\Users\Tom\VSCodeProjects\personal\webpack-test\node_modules\@types\react-router\lib\useRouterHistory.d.ts:1:34
Module '"C:/Users/Tom/VSCodeProjects/personal/webpack-test/node_modules/history/lib/index"' has no exported member 'HistoryQueries'.

ERROR in [default] C:\Users\Tom\VSCodeProjects\personal\webpack-test\node_modules\@types\react-router\lib\useRouterHistory.d.ts:1:50
Module '"C:/Users/Tom/VSCodeProjects/personal/webpack-test/node_modules/history/lib/index"' has no exported member 'CreateHistory'.

ERROR in [default] C:\Users\Tom\VSCodeProjects\personal\webpack-test\node_modules\@types\react-router\lib\useRoutes.d.ts:4:47
Module '"C:/Users/Tom/VSCodeProjects/personal/webpack-test/node_modules/history/lib/index"' has no exported member 'CreateHistory'.

ERROR in [default] C:\Users\Tom\VSCodeProjects\personal\webpack-test\node_modules\@types\react-router\lib\useRoutes.d.ts:4:68
Module '"C:/Users/Tom/VSCodeProjects/personal/webpack-test/node_modules/history/lib/index"' has no exported member 'CreateHistory'.
4

2 回答 2

0

您可以尝试"exclude": [ "node_modules" ]在您的tsconfig.json.

于 2016-10-19T12:45:30.037 回答
0

我的建议是检查每个 webpack 加载器,并确保它们不会以某种方式导致这种情况发生。我有一个类似的问题,我能够通过使用与以前不同的 CSS 加载器(sass)来解决它。

于 2021-06-30T20:07:31.563 回答