【问题标题】:morris.js and raphael.js , node_module not foundmorris.js 和 raphael.js ,找不到 node_module
【发布时间】:2018-02-17 02:45:52
【问题描述】:

我有一个 Angular 项目,我正在使用 morris.js。我的 package.json 引用了 morris 和 raphael,如下所示:

dependencies{
....
"raphael": "^2.2.7",
    "morris.js": "0.5.0",
....
}

我还检查了 node_module 文件夹,两个依赖项都存在。在 mycomponent.ts 中,我正在这样做:

import  'morris.js';

export class mycomponent implements OnInit {
areaChart: morris.GridChart;

.....
 this.areaChart = Morris.Area({
.....)}

}

我收到“ERROR ReferenceError: Raphael is not defined”的错误

当它在做 this.raphael = new Raphael(this.el[0]); 时,它被 morris.js 解雇了

我应该如何在 Morris 中加入 Raphael 以使其发挥作用?

【问题讨论】:

  • 但是你的 raphael.js 和 morris.js 是在 index.html 中加载的吗???即如果它的 angular cli 项目比你包含在你的 angular-cli.json 中?
  • 我有 index.html,但它是一个带有 webpack 的 Angular 4 项目。所以他们不会在 index.html 中包含 js 文件。我尝试在 mycomponent .ts 中添加“import raphael”,但没有帮助。
  • 在你的 index.html 中添加 raphael.js 和 morris.js...!
  • 这不是正确的做法..
  • 我有 webpack.dev.js 和 webpack.common.js..它们都太大了,请告诉我如何将它们发送给您?你也确定,它们是外部js ..我在我的component.ts中导入了其他js,如下所示:import 'morris.js';导入'jquery-knob';导入“引导日期选择器”;导入'jqueryui';导入“日期范围选择器”;导入'jquery-slimscroll';导入“拉斐尔”;导入'admin-lte';并且所有这些都在工作..只有 raphael 不工作...不同之处在于 rappahel 是从 morris.js 内部引用的,这是 node_module 中的另一个库

标签: angular webpack raphael package.json


【解决方案1】:

我遇到了同样的问题,我通过添加:

new webpack.ProvidePlugin({ Raphael: 'raphael' })

到我的 webpack.config.js 插件部分,使 Raphael 全球可用。 我还添加了:

new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', jquery: 'jquery' })

之前,jQuery 也可以在全球范围内工作。

【讨论】:

  • 我在提供插件中有 jquery。 .. 也会为 Raphael 试试这个
  • 天哪!它起作用了...您不会相信我尝试过的所有事情...我尝试创建别名,例如 morris alias: { 'morris.js': 'morris.js/morris.js' } 尝试更改,morris.js 非常感谢!!
  • 我有同样的问题,但我只使用 angular-cli。我该如何解决这个问题?
  • 谢谢!对于 Ionic 3 项目,要修改的文件是 node_modules/@ionic/app-scripts/config/webpack.config.js
猜你喜欢
  • 2016-11-15
  • 1970-01-01
  • 2011-05-05
  • 1970-01-01
  • 1970-01-01
  • 2016-01-02
  • 1970-01-01
  • 2012-05-14
  • 1970-01-01
相关资源
最近更新 更多