【问题标题】:Angular 1.x ES6 Webpack include 3rd party librariesAngular 1.x ES6 Webpack 包含 3rd 方库
【发布时间】:2017-01-12 02:45:00
【问题描述】:

我正在使用入门项目开发应用程序:https://github.com/shprink/angular1.4-ES6-material-webpack-boilerplate

当我需要使用 3rd 方库时,我被卡住了。 我想用js-yaml https://github.com/nodeca/js-yaml

我尝试将它添加到我的角度服务中:

import jsyaml from  '../../node_modules/js-yaml/bin/js-yaml.js';

但我得到错误:

bundle-0d6476.js:75756 Uncaught Error: Cannot find module "../../node_modules/js-yaml/bin/js-yaml.js"

我该如何解决这个问题?

【问题讨论】:

    标签: javascript angularjs ecmascript-6 webpack


    【解决方案1】:

    检查the docs on resolving modules。要从node_modules 导入模块,请指定路径,省略直到node_modules 并包括所有内容。因此,import jsyaml from 'js-yaml/bin/js-yaml.js' 应该可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-03
      • 2017-04-10
      • 1970-01-01
      • 2016-06-08
      • 1970-01-01
      • 2017-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多