問題背景
我正在嘗試將 Wallet Connect 添加到我們的專案(Vue.js)中,在此處形成:https ://docs.walletconnect.com/quick-start/dapps/web3-provider ,我使用此命令安裝它。
將其匯入我的 js 檔案中
import Web3 from 'web3'
import WalletConnectProvider from '@walletconnect/web3-provider'
它顯示了這些錯誤:
ERROR Failed to compile with 7 errors
These dependencies were not found:
* crypto in ./node_modules/eth-lib/lib/bytes.js, ./node_modules/web3-eth-accounts/lib/index.js and 1 other
* http in ./node_modules/xhr2-cookies/dist/xml-http-request.js
* https in ./node_modules/xhr2-cookies/dist/xml-http-request.js
To install them, you can run: npm install --save crypto http https
嘗試
我安裝這些軟體包。
npm i crypto-browserify
npm i https-browserify
npm i stream-http
然后編輯我的vue.config.js檔案:
resolve: {
fallback: {
crypto: require.resolve('crypto-browserify'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
},
},
并且錯誤變為:
WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
configuration.resolve has an unknown property 'fallback'.
These properties are valid:
object { alias?, aliasFields?, cachePredicate?, cacheWithContext?, concord?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, resolver?, symlinks?, unsafeCache?, useSyncFileSystemCalls? }
這是我的package.json檔案的樣子:
{
"dependencies": {
"@walletconnect/web3-provider": "^1.7.8",
"crypto-browserify": "^3.12.0",
"https-browserify": "^1.0.0",
"os": "^0.1.2",
"stream": "^0.0.2",
"stream-http": "^3.2.0",
"vue": "^2.6.10",
"web3": "^1.7.3",
},
"devDependencies": {
"@vue/cli-service": "^3.7.0",
"webpack": "^4.39.3",
"webpack-bundle-analyzer": "^3.6.0",
"webpack-dev-server": "^3.11.2",
"webpack-merge": "^4.2.1",
"webpack-node-externals": "^1.7.2",
"webpack-plugin-hash-output": "^3.2.1",
"webpack-spritesmith": "^1.0.1",
}
}
而我的node版本是v10.24.1,暫時還不能升級。
v10.24.1
從上面可以看出,我已經從錯誤(、、和)中安裝了建議的包crypto-browserify,stream-http并將https-browserify它們包含在vue.config.js.
我該如何解決這個問題?
uj5u.com熱心網友回復:
您正在使用 Webpack 4。該fallback選項僅從 Webpack>=5.0.0開始可用。
對于 Webpack 4,請考慮使用alias選項。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/481602.html
下一篇:安裝ng-bootstrap
