简体   繁体   English

导入第三方js lib

[英]Import third party js lib

I would like to use a js-lib in my project which is on my local machine.我想在我的本地机器上的项目中使用 js-lib。

first of all I imported it in a simple basic index.html like this:首先,我将它导入到一个简单的基本 index.html 中,如下所示:

<script type="text/javascript" src="../../sdk/frontendSDK-develop.js"></script>

and it worked fine.它工作正常。

Now I want to import it in my React App.现在我想将它导入到我的 React 应用程序中。

So I tried to import it the same way in my public/index.html like:所以我尝试在我的 public/index.html 中以相同的方式导入它,例如:

<script type="text/javascript" src="../../sdk/frontendSDK-develop.js"></script>

the file is loaded but it is not in the window object and in the console I have the error:该文件已加载,但它不在窗口对象中,并且在控制台中出现错误:

Uncaught SyntaxError: Unexpected token '<'

I also tried to import it with我也尝试导入它

<script type="text/babel" src="../../sdk/frontendSDK-develop.js"></script>

No more error in the console but the script will also not be loaded.控制台中不再出现错误,但脚本也不会加载。

Any suggestions?有什么建议?

您也可以在 app.js 文件中导入外部库。

The problem was the path.问题是路径。 It is not allowed to go outside of the dir where the index.html file is.不允许超出 index.html 文件所在的目录。 I had to move my .js file in to a folder under the index.html我不得不将我的 .js 文件移动到 index.html 下的文件夹中

So I had to change the import from所以我不得不改变进口

<script type="text/javascript" src="../../sdk/frontendSDK-develop.js"></script>

to

<script type="text/javascript" src="./sdk/frontendSDK-develop.js"></script>

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

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