简体   繁体   English

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

[英]Uncaught ReferenceError : require is not defined - Chart.js

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 图片

in your code, pull the bundle instead. 在你的代码中,改为拉取包。 Eg ~/Plugin/Chart.js/dist/Chart.bundle.js 例如〜/ Plugin / Chart.js / dist / Chart.bundle.js

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

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

First include the require.js file then use RequireJS . 首先包括require.js文件,然后使用RequireJS You can download here . 你可以在这里下载。

I had the same problem after installing with Bower. 安装Bower后我遇到了同样的问题。

The solution as proposed in https://github.com/jtblin/angular-chart.js/issues/466 was 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(使用角度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 install again 3-现在再次运行bower install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM