如何使用包裹/Netlify导入JavaScript库?

发布于 2025-02-13 09:02:35 字数 465 浏览 0 评论 0原文

我正在构建一个香草JS应用程序并使用CDN的工作正常运行,但是如果我安装了带有npm的typed.js的应用程序,然后将其导入为从'typed.js' import ofimpt ofimpt>它应该在本地开发服务器上。

但是,一旦我推开它,并且它是基于Netlify的,我会发现一个控制台错误,说明: 无法解析模块指定符“ typed.js”。相对引用必须以“/”,“ ./”或“ ../” ../".开始,

我尝试以各种方式更改导入,例如'typed''/typed''/typed.js''typed.js''typed.js/lib/typed.js'typed.js/src/typed.js'等,并使用require而不是导入。

I'm building a vanilla js app and using CDN's works fine, but If I install an app like typed.js with npm, and then import it as import typed from 'typed.js' it works as it should on a local dev server.

However, once I push it and it's built on Netlify I get a console error stating:
failed to resolve module specifier "typed.js". relative references must start with either "/", "./", or "../".

I have tried changing the import in every way I can think of like 'typed' , '/typed' , '/typed.js' , 'typed.js' , 'typed.js/lib/typed.js' , typed.js/src/typed.js' etc and using require instead of import.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铜锣湾横着走 2025-02-20 09:02:35

它最终是Netlify的一个非常简单的修复,我需要将发布目录更改为构建设置中的“区域”。

It ended up being a very easy fix with Netlify, I needed to change the publish directory to "dist" within the build settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文