我刚刚开始使用 CoinGecko API,但我第一次调用/ping
. 它给了我错误Module not found: Error: Can't resolve 'https'
。知道为什么会这样吗?我正在用反应做,这里是代码:
项目/src/App.js
import { useEffect } from 'react';
import axios from 'axios';
// import CoinGecko from 'coingecko-api/lib/CoinGecko';
const CoinGecko = require("coingecko-api");
function App() {
useEffect(() => {
const CoinGeckoClient = new CoinGecko();
async function pingAPI(){
const response = await CoinGeckoClient.ping();
console.log(response)
return response
}
pingAPI()
}, [])
return (
<div>Hello world</div>
)
}
export default App;
这是完整的堆栈跟踪:
Compiled with problems:X
ERROR in ./node_modules/coingecko-api/lib/CoinGecko.js 3:14-30
Module not found: Error: Can't resolve 'https' in '/Users/romunoz/Documents/code/javascript/cryptoapp/node_modules/coingecko-api/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
- install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "https": false }
ERROR in ./node_modules/coingecko-api/lib/CoinGecko.js 5:20-42
Module not found: Error: Can't resolve 'querystring' in '/Users/romunoz/Documents/code/javascript/cryptoapp/node_modules/coingecko-api/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "querystring": require.resolve("querystring-es3") }'
- install 'querystring-es3'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "querystring": false }