简体   繁体   English

如何使用 Parcel/Netlify 导入 javascript 库?

[英]How to import javascript libraries using Parcel/Netlify?

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.我正在构建一个 vanilla js 应用程序并使用 CDN 工作正常,但是如果我使用 npm 安装一个类似 typed.js 的应用程序,然后将其import typed from 'typed.js' ,它可以在本地开发服务器上正常工作.

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 "../".但是,一旦我推送它并且它是基于 Netlify 构建的,我会收到一个控制台错误说明: failed to resolve module specifier "typed.js". relative references must start with either "/", "./", or "../". 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.我尝试以我能想到的各种方式更改导入,例如'typed''/typed''/typed.js''typed.js''typed.js/lib/typed.js'typed.js/src/typed.js'等并使用 require 而不是 import。

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

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

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