带有打字稿的Webpack没有找到入口模块

时间:2017-01-21 22:53:06

标签: angular typescript webpack

我正在尝试将webpack集成到我的打字稿应用程序中。为了学习webpack,我试图进行最小的迁移。所以我克隆了Angular2 quickstart seed,添加了一个webpack.config.js:

'use strict';
let path = require('path');

module.exports = {
    entry: './app/main.ts',
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                loader: 'awesome-typescript-loader',
                exclude: /node_modules/,
            },
        ]
    },
    output: {
        filename: '/bundle.js',
        path: path.resolve(__dirname, 'dist')
    },
    resolve: {
        extensions: [".tsx", ".ts", ".js"]
    },
};

尝试构建:

PS C:\Users\ltheisen\git\pastdev-test-webpack> .\node_modules\.bin\webpack --display-error-details
Hash: 954fdea72e6d10e35648
Version: webpack 1.14.0
Time: 31ms

ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory' ./app/main.ts in C:\Users\ltheisen\git\pastdev-test-webpack
resolve file
  C:\Users\ltheisen\git\pastdev-test-webpack\app\main.ts.tsx doesn't exist
  C:\Users\ltheisen\git\pastdev-test-webpack\app\main.ts.ts doesn't exist
  C:\Users\ltheisen\git\pastdev-test-webpack\app\main.ts.js doesn't exist
resolve directory
  C:\Users\ltheisen\git\pastdev-test-webpack\app\main.ts\package.json doesn't exist (directory description file)
  C:\Users\ltheisen\git\pastdev-test-webpack\app\main.ts is not a directory (directory default file)

--display-error-details输出中,我可以看到它使用resolve.extensions的所有3个扩展名检查文件,但不检查文件本身。我找到的所有示例都使用的文件的扩展名为entrywebpack basic setuptypescript integrating with build tools,...)。如果我删除扩展名,webpack构建会找到entry文件(虽然我似乎还有其他问题......)。

无论如何,我的问题是:我做错了吗?缺少明显的东西?或者文档错了吗?

----更新---- 看来npmjs存储库可能有问题。具体来说,webpack 2 documentation for installation说:

npm install webpack --save-dev

但是,npmjs显示版本1.14.0为当前版本:

enter image description here

这看起来很奇怪,因为2.2.0版本是在上周发布的......但我想这个版本还没有传播到npmjs?更新到webpack 2后,这似乎解决了我的问题......

2 个答案:

答案 0 :(得分:1)

npm显示上次发布的版本,使用notification查找所有版本。

答案 1 :(得分:1)

Webpack 2一直处于预发布阶段,直到此刻。我不能说为什么2.2.0如果被认为是不稳定的,也没有相应的标记,但它是以这种方式发布的,npm dist-tag ls webpack输出:

  

beta:2.2.0

     

最新:1.14.0

使用适当的semver进行安装:

npm install webpack@2 --save-dev