Javascript 未捕获的 ReferenceError : require 未定义 - Chart.js

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38176769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:09:26  来源:igfitidea点击:

Uncaught ReferenceError : require is not defined - Chart.js

javascriptjqueryjquery-pluginschart.js

提问by Ken.N

I use Chart.js(new version) as :

我使用 Chart.js(新版本)作为:

<script src="~/Plugin/Chart.js/src/chart.js"></script>

But when i demo in chrome, i get a error :

但是当我在 chrome 中演示时,我收到一个错误:

chart.js:4 Uncaught ReferenceError: require is not defined

Image

图片

回答by derp

in your code, pull the bundle instead. E.g ~/Plugin/Chart.js/dist/Chart.bundle.js

在您的代码中,改为拉取捆绑包。例如 ~/Plugin/Chart.js/dist/Chart.bundle.js

回答by James

Use Chart.bundle.min.js bundle found on this page: https://cdnjs.com/libraries/Chart.js

使用在此页面上找到的 Chart.bundle.min.js 包:https://cdnjs.com/libraries/Chart.js

https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.bundle.min.js

https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.bundle.min.js

回答by himanshupareek66

For the Angular CLI users -> No need to add this script in angular-cli.json file, because angular-cli should pack ng2-charts lib(and other from node_modules) and add it automatically to your index.html.

对于 Angular CLI 用户 -> 不需要在 angular-cli.json 文件中添加这个脚本,因为 angular-cli 应该打包 ng2-charts lib(以及来自 node_modules 的其他)并自动添加到你的 index.html 中。

https://github.com/valor-software/ng2-charts/issues/832

https://github.com/valor-software/ng2-charts/issues/832

回答by scsiva1991

First include the require.jsfile then use RequireJS. You can download here.

首先包含require.js文件,然后使用RequireJS。你可以在这里下载。

回答by rafahoro

I had the same problem after installing with Bower.

使用 Bower 安装后我遇到了同样的问题。

The solution as proposed in https://github.com/jtblin/angular-chart.js/issues/466was to get specific versions of chart.js and angular-chart.js (tested with angular 1.4.0)

https://github.com/jtblin/angular-chart.js/issues/466中提出的解决方案是获取特定版本的chart.js 和angular-chart.js(使用angular 1.4.0 测试)

If you use Bower, try this in your bower.json

如果您使用 Bower,请在您的 bower.json 中尝试此操作

"chart.js": "npm:chart.js#2.1.0",
"angular-chart.js": "1.0.1"

and then run: bower install

然后运行: bower install



If npm:chart.js is not working for you, you need to use a resolver.

如果 npm:chart.js 不适合你,你需要使用解析器。

1- Add to your .bowerrc:

1- 添加到您的 .bowerrc:

{
  "resolvers": [
    "bower-npm-resolver"
  ]
}

2- Install bower-npm-resolver

2- 安装 bower-npm-resolver

npm install -g bower-npm-resolver

3- Now run bower installagain

3-现在bower install再次运行