如何使用包裹/Netlify导入JavaScript库?
我正在构建一个香草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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它最终是Netlify的一个非常简单的修复,我需要将发布目录更改为构建设置中的“区域”。
It ended up being a very easy fix with Netlify, I needed to change the publish directory to "dist" within the build settings.