【问题标题】:jquery.js and jquery.keyframes.js are not found when using NPM使用 NPM 时找不到 jquery.js 和 jquery.keyframes.js
【发布时间】:2022-01-17 01:02:39
【问题描述】:

我在使用 jquery 和 jquery.keyframes 时遇到问题。我使用 NPM,js 文件存储在 node_modules 文件夹中,而 html 文件存储在 public 文件夹中。由于某种原因,当我使用此代码时,html 文件找不到 js 文件:

<script src="../node_modules/jquerykeyframes/dist/jquery.keyframes.js"></script>
<script src="../node_modules/jquery/dist/jquery.js"></script>

我尝试了一些替代方案,但都没有奏效。我做错了什么?

【问题讨论】:

    标签: javascript html node.js node-modules


    【解决方案1】:

    您不应该以这种方式导入您的 node_modules。您可以使用节点导入/导出(或要求)设置脚本,也可以像这样使用 jquery cdn (https://code.jquery.com/):

    <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
    

    这里是 jquery keyframes cdn 的链接:https://cdnjs.com/libraries/jquerykeyframes

    【讨论】:

    • 现在我在 jquery.keyframes 得到“未捕获的 TypeError:url.indexOf 不是 jQuery.fn.init.jQuery.fn.load (jquery-3.6.0.js:10363) 的函数。 js:7 在 jquery.keyframes.js:184"
    • 如果您能分享您的代码,那将非常有帮助。问题是你不需要 jquery.keyframes.js。你应该在窗口加载时执行你的代码,就像这样: $(window).on('load', function(){ ...});
    • 添加:
    • 我看了看,发现你有所有这些你没有使用的 npm 包。问题是您的 html 页面中有所有这些脚本标签,但这与您安装的 npm 包无关。您必须在脚本文件中导入您的包,然后才能使用 npm 包。
    • 是的,该项目最初是基于一个包含所有这些 npm 包的模板,所以我稍后会坐下来删除那些不需要的。
    猜你喜欢
    • 1970-01-01
    • 2016-02-25
    • 2017-05-14
    • 2014-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-07
    • 2014-01-30
    相关资源
    最近更新 更多