react fecth 本地 json
出现 Unexpected token < in JSON at position 0,将文件放到 public目录下
async 和 await 无法识别
Uncaught ReferenceError: regeneratorRuntime is not defined
原因:使用 ES7 async/await 报错,浏览器不能识别
解决方法:
安装 babel-plugin-transform-runtime
yarn add --dev babel-plugin-transform-runtime
.babelsrc添加 配置"plugins": [["transform-runtime",{"helpers": false,"polyfill": false,"regenerator": true,"moduleName": "babel-runtime"}]]
Echart 无法打开
C:\Windows\System32\drivers\etc 下 host 添加一下命令
151.101.2.132 echarts.apache.org
vue3 项目 安装 web3js 报错
Module not found: Error: Can't resolve 'assert' in '*/node_modules/ethereumjs-util/dist'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: { "assert": require.resolve("assert/") }'- install 'assert'If you don't want to include a polyfill, you can use an empty module like this:resolve.fallback: { "assert": false }
将日志中需要 resolve.fallback的插件汇总,汇总后安装
yarn add --dev stream-http https-browserify crypto-browserify stream-browserify os-browserify url assert
在vue.config.js 中添加如下配置
module.exports = defineConfig({configureWebpack: {plugins: [new webpack.ProvidePlugin({Buffer: ['buffer', 'Buffer'],process: 'process/browser'})],resolve: {fallback: {http: require.resolve('stream-http'),https: require.resolve('https-browserify'),crypto: require.resolve('crypto-browserify'),stream: require.resolve('stream-browserify'),os: require.resolve('os-browserify/browser'),url: require.resolve('url'),assert: require.resolve('assert')}}}})
安装 buffer 和 wepack
Error: EBUSY: resource busy or locked, rmdir
npm cache verify
Vue3 import web3 fail
方法 1 : Polyfill Node globals/modules
思路:web3 配置兼容性,使其能在浏览器使用
安装以下两个插件
yarn add @esbuild-plugins/node-globals-polyfill --devyarn add @esbuild-plugins/node-modules-polyfill --dev
配置 optimizeDeps.esbuildOptions 使用 ESBuild 插件,通过 define 替换 globalThis
引入了 polyfill 包,导致打包体积增大
方法 2: Use pre-bundled script
思路:web3 打包后的dist可以直接在浏览器运行
- 配置 alias 指向这个文件 ```javascript import { defineConfig } from ‘vite’
export default defineConfig({ ⋮ resolve: { alias: { web3: ‘web3/dist/web3.min.js’, },
// oralias: [{find: 'web3',replacement: 'web3/dist/web3.min.js',},],
}, })
[在线 demo](https://stackblitz.com/edit/vue3-web3-demo-w1lkev?file=vite.config.ts)> 直接引用 dist ,体积更小参考链接:[web3js-fails-to-import-in-vue3-composition-api-project](https://stackoverflow.com/questions/68975837/web3js-fails-to-import-in-vue3-composition-api-project/69021714#69021714)<a name="hJ2Ym"></a>## Sass 问题<a name="fKo0C"></a>### Module build failed: TypeError: this.getResolve is not a functionsass-loader 版本过高,降级到 ^7.3```cssyarn add sass-loader@^7.3
PancakeSwap 安装依赖错误分析
错误分析 - 阶段1
错误日志
warning Error running install script for optional dependency: "D:\\tk\\company\\dccswap_front_swap\\node_modules\\sqlite3: Command failed.Exit code: 1Command: node-pre-gyp install --fallback-to-buildArguments:Directory: D:\\tk\\company\\dccswap_front_swap\\node_modules\\sqlite3Output:node-pre-gyp info it worked if it ends with oknode-pre-gyp info using node-pre-gyp@0.11.0node-pre-gyp info using node@16.16.0 | win32 | x64node-pre-gyp WARN Using request for node-pre-gyp https downloadnode-pre-gyp info check checked for \"D:\\tk\\company\\dccswap_front_swap\\node_modules\\sqlite3\\lib\\binding\\node-v93-win32-x64\\node_sqlite3.node\" (not found)node-pre-gyp http GET https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.2.0/node-v93-win32-x64.tar.gznode-pre-gyp http 403 https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.2.0/node-v93-win32-x64.tar.gznode-pre-gyp WARN Tried to download(403): https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.2.0/node-v93-win32-x64.tar.gznode-pre-gyp WARN Pre-built binaries not found for sqlite3@4.2.0 and node@16.16.0 (node-v93 ABI, unknown) (falling back to source compile with node-gyp)node-pre-gyp http 403 status code downloading tarball https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.2.0/node-v93-win32-x64.tar.gzgyp info it worked if it ends with okgyp info using node-gyp@8.4.1gyp info using node@16.16.0 | win32 | x64gyp info okgyp info it worked if it ends with okgyp info using node-gyp@8.4.1gyp info using node@16.16.0 | win32 | x64gyp ERR! find Pythongyp ERR! find Python Python is not set from command line or npm configurationgyp ERR! find Python Python is not set from environment variable PYTHONgyp ERR! find Python checking if \"python3\" can be usedgyp ERR! find Python - \"python3\" is not in PATH or produced an errorgyp ERR! find Python checking if \"python\" can be usedgyp ERR! find Python - \"python\" is not in PATH or produced an errorgyp ERR! find Python checking if Python is C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python39\\python.exegyp ERR! find Python - \"C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python39\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Program Files\\Python39\\python.exegyp ERR! find Python - \"C:\\Program Files\\Python39\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python39-32\\python.exegyp ERR! find Python - \"C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python39-32\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Program Files\\Python39-32\\python.exegyp ERR! find Python - \"C:\\Program Files\\Python39-32\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Program Files (x86)\\Python39-32\\python.exegyp ERR! find Python - \"C:\\Program Files (x86)\\Python39-32\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python38\\python.exegyp ERR! find Python - \"C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python38\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Program Files\\Python38\\python.exegyp ERR! find Python - \"C:\\Program Files\\Python38\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exegyp ERR! find Python - \"C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Program Files\\Python38-32\\python.exegyp ERR! find Python - \"C:\\Program Files\\Python38-32\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Program Files (x86)\\Python38-32\\python.exegyp ERR! find Python - \"C:\\Program Files (x86)\\Python38-32\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python37\\python.exegyp ERR! find Python - \"C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python37\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Program Files\\Python37\\python.exegyp ERR! find Python - \"C:\\Program Files\\Python37\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exegyp ERR! find Python - \"C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Program Files\\Python37-32\\python.exegyp ERR! find Python - \"C:\\Program Files\\Python37-32\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Program Files (x86)\\Python37-32\\python.exegyp ERR! find Python - \"C:\\Program Files (x86)\\Python37-32\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python36\\python.exegyp ERR! find Python - \"C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python36\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Program Files\\Python36\\python.exegyp ERR! find Python - \"C:\\Program Files\\Python36\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python36-32\\python.exegyp ERR! find Python - \"C:\\Users\\fetk\\AppData\\Local\\Programs\\Python\\Python36-32\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Program Files\\Python36-32\\python.exegyp ERR! find Python - \"C:\\Program Files\\Python36-32\\python.exe\" could not be rungyp ERR! find Python checking if Python is C:\\Program Files (x86)\\Python36-32\\python.exegyp ERR! find Python - \"C:\\Program Files (x86)\\Python36-32\\python.exe\" could not be rungyp ERR! find Python checking if the py launcher can be used to find Python 3gyp ERR! find Python - \"py.exe\" is not in PATH or produced an errorgyp ERR! find Pythongyp ERR! find Python **********************************************************gyp ERR! find Python You need to install the latest version of Python.gyp ERR! find Python Node-gyp should be able to find and use Python. If not,gyp ERR! find Python you can try one of the following options:gyp ERR! find Python - Use the switch --python=\"C:\\Path\\To\\python.exe\"gyp ERR! find Python (accepted by both node-gyp and npm)gyp ERR! find Python - Set the environment variable PYTHONgyp ERR! find Python - Set the npm configuration variable python:gyp ERR! find Python npm config set python \"C:\\Path\\To\\python.exe\"gyp ERR! find Python For more information consult the documentation at:gyp ERR! find Python https://github.com/nodejs/node-gyp#installationgyp ERR! find Python **********************************************************gyp ERR! find Pythongyp ERR! configure errorgyp ERR! stack Error: Could not find any Python installation to usegyp ERR! stack at PythonFinder.fail (D:\\tk\\company\\dccswap_front_swap\\node_modules\\node-gyp\\lib\\find-python.js:330:47)gyp ERR! stack at PythonFinder.runChecks (D:\\tk\\company\\dccswap_front_swap\\node_modules\\node-gyp\\lib\\find-python.js:159:21)gyp ERR! stack at PythonFinder.<anonymous> (D:\\tk\\company\\dccswap_front_swap\\node_modules\\node-gyp\\lib\\find-python.js:228:18)gyp ERR! stack at PythonFinder.execFileCallback (D:\\tk\\company\\dccswap_front_swap\\node_modules\\node-gyp\\lib\\find-python.js:294:16)gyp ERR! stack at exithandler (node:child_process:406:5)gyp ERR! stack at ChildProcess.errorhandler (node:child_process:418:5)gyp ERR! stack at ChildProcess.emit (node:events:527:28)gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)gyp ERR! stack at onErrorNT (node:internal/child_process:478:16)gyp ERR! stack at processTicksAndRejections (node:internal/process/task_queues:83:21)...
错误信息
- sqlit3 安装失败,依赖所在包404
- gyp ERR! find Python 没有找到 python
- node-pre-gyp ERR! System Windows_NT 10.0.22000
方案:先解决 python 错误,再看错误信息
gyp ERR! find Python - 没有找到 python
根据 find python的报错信息,推断需要安装 >= 3.6.0 以上的python 版本。
我是通过安装 3.6.0 以下版本,它提示得出,并不是推断得出
下载地址:https://www.python.org/downloads/windows/
解决:
- 安装 python
- 配置 环境变量
- cmd 通过 python命令 检测是否安装成功
sqlite 3 安装失败
方案:版本降到 14.15.0
nvm use 14.15.0
错误分析 - 阶段2
错误日志
gyp ERR! find VSgyp ERR! find VS msvs_version not set from command line or npm configgyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Promptgyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more detailsgyp ERR! find VS looking for Visual Studio 2015gyp ERR! find VS - not foundgyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8gyp ERR! find VSgyp ERR! find VS **************************************************************gyp ERR! find VS You need to install the latest version of Visual Studiogyp ERR! find VS including the \"Desktop development with C++\" workload.gyp ERR! find VS For more information consult the documentation at:gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windowsgyp ERR! find VS **************************************************************gyp ERR! find VSgyp ERR! configure errorgyp ERR! stack Error: Could not find any Visual Studio installation to usegyp ERR! stack at VisualStudioFinder.fail (D:\\tk\\company\\dccswap_front_swap\\node_modules\\node-gyp\\lib\\find-visualstudio.js:122:47)gyp ERR! stack at D:\\tk\\company\\dccswap_front_swap\\node_modules\\node-gyp\\lib\\find-visualstudio.js:75:16gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (D:\\tk\\company\\dccswap_front_swap\\node_modules\\node-gyp\\lib\\find-visualstudio.js:363:14)gyp ERR! stack at D:\\tk\\company\\dccswap_front_swap\\node_modules\\node-gyp\\lib\\find-visualstudio.js:71:14gyp ERR! stack at D:\\tk\\company\\dccswap_front_swap\\node_modules\\node-gyp\\lib\\find-visualstudio.js:384:16gyp ERR! stack at D:\\tk\\company\\dccswap_front_swap\\node_modules\\node-gyp\\lib\\util.js:54:7gyp ERR! stack at D:\\tk\\company\\dccswap_front_swap\\node_modules\\node-gyp\\lib\\util.js:33:16gyp ERR! stack at ChildProcess.exithandler (child_process.js:315:5)gyp ERR! stack at ChildProcess.emit (events.js:315:20)gyp ERR! stack at maybeClose (internal/child_process.js:1048:16)gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)gyp ERR! System Windows_NT 10.0.22000gyp ERR! command \"C:\\\\Program Files\\\\nodejs\\\\node.exe\" \"D:\\\\tk\\\\company\\\\dccswap_front_swap\\\\node_modules\\\\node-gyp\\\\bin\\\\node-gyp.js\" \"configure\" \"--fallback-to-build\" \"--module=D:\\\\tk\\\\company\\\\dccswap_front_swap\\\\node_modules\\\\sqlite3\\\\lib\\\\binding\\\\node-v83-win32-x64\\\\node_sqlite3.node\" \"--module_name=node_sqlite3\" \"--module_path=D:\\\\tk\\\\company\\\\dccswap_front_swap\\\\node_modules\\\\sqlite3\\\\lib\\\\binding\\\\node-v83-win32-x64\" \"--napi_version=7\" \"--node_abi_napi=napi\" \"--napi_build_version=0\" \"--node_napi_label=node-v83\"gyp ERR! cwd D:\\tk\\company\\dccswap_front_swap\\node_modules\\sqlite3gyp ERR! node -v v14.15.0gyp ERR! node-gyp -v v8.4.1gyp ERR! not oknode-pre-gyp ERR! build errornode-pre-gyp ERR! stack Error: Failed to execute 'C:\\Program Files\\nodejs\\node.exe D:\\tk\\company\\dccswap_front_swap\\node_modules\\node-gyp\\bin\\node-gyp.js configure --fallback-to-build --module=D:\\tk\\company\\dccswap_front_swap\\node_modules\\sqlite3\\lib\\binding\\node-v83-win32-x64\\node_sqlite3.node --module_name=node_sqlite3 --module_path=D:\\tk\\company\\dccswap_front_swap\\node_modules\\sqlite3\\lib\\binding\\node-v83-win32-x64 --napi_version=7 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v83' (1)node-pre-gyp ERR! stack at ChildProcess.<anonymous> (D:\\tk\\company\\dccswap_front_swap\\node_modules\\node-pre-gyp\\lib\\util\\compile.js:83:29)node-pre-gyp ERR! stack at ChildProcess.emit (events.js:315:20)node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:1048:16)node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)node-pre-gyp ERR! System Windows_NT 10.0.22000node-pre-gyp ERR! command \"C:\\\\Program Files\\\\nodejs\\\\node.exe\" \"D:\\\\tk\\\\company\\\\dccswap_front_swap\\\\node_modules\\\\node-pre-gyp\\\\bin\\\\node-pre-gyp\" \"install\" \"--fallback-to-build\"node-pre-gyp ERR! cwd D:\\tk\\company\\dccswap_front_swap\\node_modules\\sqlite3node-pre-gyp ERR! node -v v14.15.0node-pre-gyp ERR! node-pre-gyp -v v0.11.0node-pre-gyp ERR! not okFailed to execute 'C:\\Program Files\\nodejs\\node.exe D:\\tk\\company\\dccswap_front_swap\\node_modules\\node-gyp\\bin\\node-gyp.js configure --fallback-to-build --module=D:\\tk\\company\\dccswap_front_swap\\node_modules\\sqlite3\\lib\\bin$ husky installhusky - Git hooks installedDone in 30.81s.
错误信息
- sqlit3 安装失败,依赖所在包404
- gyp ERR! find VS - vs 模块缺失
- node-pre-gyp ERR! System Windows_NT 10.0.22000
vs模块缺失
解决:安装 window-build-tools(安装后要重启)
npm install --global --production windows-build-tools
TypeScript Error
ts(2349)
错误复现伪代码
export default function useBoolean(def = false) {// ***return [isBoolean, exchangeBoolean]}const [isBoolean, exchangeBoolean] = useBoolean()exchangeBoolean()// error : This expression is not callable.Not all constituents of type 'Ref<boolean> | ((payload?: boolean | undefined) => void)' are callable.ts(2349)
分析:返回的是一个复合类型的数组,类型是里面元素类型的集合,不是所有类型都能函数调用,需要把类型锁定。
解决:通过 const 断言
export default function useBoolean(def = false) {// ***return [isBoolean, exchangeBoolean] as const}
