简体   繁体   English

无法将JavaScript库加载到Meteor应用程序中

[英]Unable to load javascript library into Meteor app

I'm having trouble using the fabric.js library with a Meteor app, and unfortunately I can't quite get past the stage of adding it to my app, much less invoking it. 我在使用带有Meteor应用程序的fabric.js库时遇到了麻烦,不幸的是我无法完全将其添加到我的应用程序中,更不用说调用它了。 The easiest recreation is as follows: 最简单的娱乐活动如下:

> mrt create test
> cd test
> mkdir client
> curl -o ./client/all.js http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.2.0/fabric.all.min.js
> mrt

Going to localhost:3000 shows the following console output: 转到localhost:3000会显示以下控制台输出:

Uncaught TypeError: Cannot read property 'object' of undefined    all.js:4074
global.fabric.global.fabric                                       all.js:4074
(anonymous function)                                              all.js:4936
(anonymous function)

And line 4074 of all.js is the second line here: all.js的第4074行是第二行:

var fabric = global.fabric || (global.fabric = { }),
    extend = fabric.util.object.extend,
    capitalize = fabric.util.string.capitalize,
    clone = fabric.util.object.clone,
    toFixed = fabric.util.toFixed,
    multiplyTransformMatrices = fabric.util.multiplyTransformMatrices;

I'm pretty certain I'm doing something wrong (as opposed to the problem being with fabric or meteor) but I'm not sure where. 我很确定我做错了(与织物或流星的问题相反)但我不确定在哪里。 I've also tried placing the all.js file into my public directory and, while that doesn't throw the same TypeError, it does make it so that the fabric variable seems to be unavailable anywhere in my code. 我也尝试将all.js文件放入我的公共目录中,虽然它没有抛出相同的TypeError,但它确实使得结构变量似乎在我的代码中的任何地方都不可用。

Any help with properly loading fabric.js into my app would be great. 将fabric.js正确加载到我的应用程序中的任何帮助都会很棒。

Would you please try to put the library file into the client/compatibility subdirectory. 您是否可以尝试将库文件放入client / compatibility子目录中。 Any javascript files imported in Meteor is wrapped in closure in which you cannot easily access the global scope. 在Meteor中导入的任何javascript文件都包含在闭包中,您无法轻松访问全局范围。 client/compatibility is the place that no closure would be applied to the library. 客户端/兼容性是不会对库应用闭包的地方。

http://docs.meteor.com/#structuringyourapp you can find more talking about the importing library issue here. http://docs.meteor.com/#structuringyourapp你可以在这里找到更多关于导入库问题的讨论。

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

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