【问题标题】:Import error of node packet in Angular2Angular2中节点数据包的导入错误
【发布时间】:2016-03-27 20:43:09
【问题描述】:

当我尝试包含 node_module angular2-google-maps 时遇到了一些奇怪的问题。我收到这些错误:

angular2-polyfills.js:1243 Uncaught SyntaxError: Unexpected token <
    Evaluating http://127.0.0.1:3000/angular2-google-maps/core
    Error loading http://127.0.0.1:3000/public/main.ts

我可以看到这个url的路径不对:http://127.0.0.1:3000/angular2-google-maps/core,应该是http://127.0.0.1:3000/node_modules/angular2-google-maps/core.js吧?

我像这样在我的组件中导入包:

import { ANGULAR2_GOOGLE_MAPS_DIRECTIVES } from 'angular2-google-maps/core';

应该是对的。我还有什么遗漏吗?

【问题讨论】:

    标签: angular


    【解决方案1】:

    如果您使用的是angular2-google-maps,则应检查example plnkr

    查看 config.js 文件,它包含以下内容

    packages: {
      'angular2-google-maps': {
        defaultExtension: 'js'
       }
    }
    

    这就是你缺少的部分。

    【讨论】:

      【解决方案2】:

      您还可以将捆绑文件 angular2-google-maps.js 包含到 HTML 条目文件的脚本标记中:

      <script src="node_modules/angular2-google-maps/bundles/ angular2-google-maps.js"></script>
      

      此文件符合 SystemJS。

      查看相应文档:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-20
        • 2017-12-01
        • 2019-12-26
        • 2020-03-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多