【问题标题】:Module not found: Error: Cannot resolve module 'angular2/bundles/angular2-polyfills'找不到模块:错误:无法解析模块“angular2/bundles/angular2-polyfills”
【发布时间】:2016-05-12 14:00:05
【问题描述】:

我正在将我的项目从 Angular2 "2.0.0-beta.17" 迁移到 Angular2 "2.0.0-rc.1"

但是在构建我的项目时出现以下错误:在 cmd 中

多个 polyfill 中的错误

找不到模块:错误:无法解析 模块 'angular2/bundles/angular2-polyfills' 在 C:\Users\akhilesh.kumar\Desktop\ang17
@多重填充

在浏览器控制台中我得到跟随错误

Uncaught Error: Cannot find module "angular2/bundles/angular2-polyfills"
Uncaught reflect-metadata shim is required when using class decorators
Uncaught TypeError: Cannot read property 'isDefaultChangeDetectionStrategy' of undefined

我的 webpack 配置如下

config.entry = isTest ? {} : {
    'polyfills': ['es6-shim/es6-shim.js', 'angular2/bundles/angular2-polyfills'],
    'vendor': './src/vendor.ts',
    'app': './src/bootstrap.ts' // our angular app
  };

config.module = {
    preLoaders: isTest ? [] : [{test: /\.ts$/, loader: 'tslint'}],
    loaders: [......],
    postLoaders: [],
    noParse: [/.+zone\.js\/dist\/.+/, /.+angular2\/bundles\/.+/, /angular2-polyfills\.js/]
  };

【问题讨论】:

    标签: typescript angular webpack


    【解决方案1】:

    Angular2 rc1 中不再有 angular-polyfills 包。您需要手动包含 ZoneJS 和 Reflect-metadata。

    例如:

    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/reflect-metadata/Reflect.js"></script>
    

    【讨论】:

    • 我很不擅长 webpack。那么这些代码呢。添加提到的脚本后我应该如何处理这些?
    • 它正在工作,但给我错误“未捕获的错误:找不到模块“angular2/bundles/angular2-polyfills”
    猜你喜欢
    • 2018-11-09
    • 2016-04-14
    • 2017-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-29
    • 1970-01-01
    相关资源
    最近更新 更多