Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

javascript - Recognizing a variable from an NPM API in CodePen

I recently used https://www.npmjs.com/package/@freezegold/covid-19 API on VSC for use of Discord bot. It included

const virus = require('@freezegold/covid-19');

and all syntax functioned and gave me the information that I wanted. Now I want to use the same NPM on CodePen to function as website instead and when I install the exact API from their NPM installer, it shows up as this

import * as FreezegoldCovid19 from "https://cdn.skypack.dev/@freezegold/covid-19@0.0.1";
virus.covid('global', (err, res) => {
  if(err) throw err
  console.log(res)
});

I am aware this new import is how ES6 works, but the error code of virus is not defined kept popping up despite me trying to figure out how to define virus, since it initially worked on my other project. Is it a syntax issue or do I need to do something else with CodePen to make this code work as it normally did using require instead of import


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

1 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...