Webpack找不到任何Angular 2模块

时间:2016-12-11 23:26:33

标签: angular typescript webpack

我正在尝试将Typescript 2中编写的简单Angular 2应用程序从Browserify迁移到Webpack 2,但是找不到有关角度模块和浏览器字段的错误。在查看了几个示例项目和教程之后,我仍然不知道可能出现什么问题。它与Browserify和Tsify很好地搭建。

ERROR in ./~/@angular/platform-browser-dynamic/index.js
Module not found: Error: Can't resolve './src/platform-browser-dynamic' in '/opt/project/node_modules/@angular/platform-browser-dynamic'
resolve './src/platform-browser-dynamic' in '/opt/project/node_modules/@angular/platform-browser-dynamic'
  using description file: /opt/project/node_modules/@angular/platform-browser-dynamic/package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: /opt/project/node_modules/@angular/platform-browser-dynamic/package.json (relative path: .)
    using description file: /opt/project/node_modules/@angular/platform-browser-dynamic/package.json (relative path: ./src/platform-browser-dynamic)
      as directory
        /opt/project/node_modules/@angular/platform-browser-dynamic/src/platform-browser-dynamic doesn't exist
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /opt/project/node_modules/@angular/platform-browser-dynamic/src/platform-browser-dynamic doesn't exist
      js
        Field 'browser' doesn't contain a valid alias configuration
        /opt/project/node_modules/@angular/platform-browser-dynamic/src/platform-browser-dynamicjs doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        /opt/project/node_modules/@angular/platform-browser-dynamic/src/platform-browser-dynamic.ts doesn't exist
[/opt/project/node_modules/@angular/platform-browser-dynamic/src/platform-browser-dynamic]
[/opt/project/node_modules/@angular/platform-browser-dynamic/src/platform-browser-dynamic]
[/opt/project/node_modules/@angular/platform-browser-dynamic/src/platform-browser-dynamicjs]
[/opt/project/node_modules/@angular/platform-browser-dynamic/src/platform-browser-dynamic.ts]
 @ ./~/@angular/platform-browser-dynamic/index.js 13:0-47
 @ ./src/main.ts
...and so on...

webpack.config.js:

module.exports = {
    entry: {
        main: './src/main.ts',
    },
    output: {
        path: './build',
        filename: '[name].js'
    },
    resolve: {
        extensions: ['js', '.ts'],
    },
    module: {
        rules: [
            {
                test: /\.ts$/,
                use: ['ts-loader'],
            }
        ]
    }
}

1 个答案:

答案 0 :(得分:1)

如果它是一个非常简单的应用程序,无论如何您都要进行更新,您可以更新以使用angular-cli。这是使用angular2的推荐方法,只要您使用最新版本它使用webpack。