我正在尝试为shopify创建一个主题应用程序扩展,我目前正在使用一个应用程序块,我需要导入一个npm包,比方说moment.js,所以我做了以下工作
import moment from "moment";但我得到了错误
Uncaught SyntaxError: Cannot use import statement outside a module所以我尝试使用require语法。
const moment = require("moment");但结果是
Uncaught ReferenceError: require is not defined这是块模板
<button id="random-button">
random label
</button>
{% schema %}
{
"name": "Random App Block",
"target": "section",
"javascript": "app.js",
"stylesheet": "style.css",
"settings":[]
}
{% endschema %}我遗漏了什么?我刚刚创建了带有Shopify CLI的应用程序,并添加了扩展,在应用程序块中导入npm包的正确方法是什么?
发布于 2022-10-11 09:00:57
好吧,这不是简单的方法,但会解决很多问题。对于每个npm包,每次都必须像以前一样(HTML/CSS/JS)添加cdn脚本,方法是转到主题->编辑主题-> Open theme.liquid之下的Layout ->添加必要的脚本。目前不可能添加npm包和导入或导出工具。
有关更多细节,请按照链接进行操作。向下滚动到最后一个答案,你就会明白了。这家伙回答得很好。
希望能帮上忙..。
https://stackoverflow.com/questions/73069014
复制相似问题