【问题标题】:Webpack with typescript not finding entry module带有打字稿的Webpack找不到入口模块
【发布时间】:2017-01-22 07:47:48
【问题描述】:

我正在尝试将 webpack 集成到我的打字稿应用程序中。为了学习 webpack,我尝试了最小的迁移。于是我克隆了Angular2quickstart 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 显示为当前版本:

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

【问题讨论】:

    标签: angular typescript webpack


    【解决方案1】:

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

    测试版:2.2.0

    最新:1.14.0

    使用合适的semver安装:

    npm install webpack@2 --save-dev
    

    【讨论】:

    • 感谢您的信息。我刚决定切换到 webpack,所以不知道它刚刚发布。刚刚看到有一个版本 2,并且文档说只需使用npm install webpack。我很自然地认为它会安装第 2 版……从那以后我学得更好了。
    【解决方案2】:

    npm 显示最后发布的版本,使用npm view webpack 查找所有版本。

    【讨论】:

      猜你喜欢
      • 2021-09-30
      • 2021-05-15
      • 1970-01-01
      • 2021-01-07
      • 2013-12-30
      • 2016-05-09
      • 1970-01-01
      相关资源
      最近更新 更多