Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

javascript - Importing UMD format third-party library into Svelte

I'm using this svelte template to create my app - degit sveltejs/template svelte-app.

I have to import a third-party library which is in UMD format and needs HTTP, HTTPS, querystring etc. Anyways, I modify my package.json to include this library and import it in App.svelte using the syntax below:

import { functionname } from 'mythirdpartylibrary/filenamewithoutexternsion';

While running npm run dev, I get the following warnings in the terminal and I'm unable to use functions defined in the third party JS file:

(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
https-proxy-agent (imported by  https-proxy-agent?commonjs-external)
url (imported by  url?commonjs-external)
http (imported by  http?commonjs-external)
querystring (imported by  querystring?commonjs-external)
https (imported by  https?commonjs-external)
(!) Missing global variable names
Use output.globals to specify browser global variable names corresponding to external modules

url (guessing 'require$$0')
http (guessing 'require$$1')
https (guessing 'require$$2')
https-proxy-agent (guessing 'require$$4')

And get the error below in the browser console:

Uncaught ReferenceError: require$$0 is not defined
    <anonymous> http://localhost:5000/build/bundle.js:481

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...