angular - 带 typescript 的 Webpack 找不到入口模块

标签 angular typescript webpack

我正在尝试将 webpack 集成到我的 typescript 应用程序中。为了学习 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 个扩展名的文件,但没有检查该文件本身。我发现的所有示例都使用扩展名为 entry 的文件( webpack 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 后,这似乎解决了我的问题...

最佳答案

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

beta: 2.2.0

latest: 1.14.0

使用适当的 semver 来安装它:

npm install webpack@2 --save-dev

关于angular - 带 typescript 的 Webpack 找不到入口模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41785408/

相关文章:

javascript - 如何过滤响应数据并使用 Angular 2/4 显示不同的值

typescript :构造函数重载

reactjs - 打包时如何减少 React 应用程序构建时间和理解 webpack 的行为

webpack - 使用 'lodash-es' 和 create-react-app 减少 bundle 中的 Lodash

typescript - 导入 google-cloud/storage 时无法调用类型缺少调用签名的表达式

javascript - eslint 'html-webpack-plugin' 应该列在项目的依赖项中,而不是 devDependencies。 (导入/无外来依赖)

javascript - 样式绑定(bind)和 ngStyle 似乎都无法在 Angular5 的 DIV 中设置背景图像

angular - 当以 5/6 Angular Angular 单击按钮时,如何从 url 下载文件

angular - 如何在 Angular 模板中显示值为 0 的 promise/observable?

Angular Aot 错误 - 如何使用对导出函数的引用替换函数