typings ~报错

使用 VS Code智能提示功能之 typings

使用步骤

————————————————
版权声明:本文为优快云博主「天马3798」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/u011127019/article/details/56671511

  1. 安装命令
npm install -g typings
  1. 查看typings的版本
typings --version
  1. 初始化
typings init

这时当前目录下会出现一个typings.json的文件

  1. 安装对应插件的提示工具
typings install dt~node --global --save
typings install dt~express --global
typings install dt~lodash --global
  1. 常用命令:
# 安装Typings的命令行代码. 
npm install typings --global

# 搜索对应模块的typings定义. 
typings search tape

# 根据名称寻找一个可获得的typings定义. 
typings search --name react

# 如果你用一个独立包的模块: 
# 或者并不是安装全局模块
# 比如并不是在命令行通过输入npm install -g typings这种方式安装的. 
typings install debug --save

# 如果是通过script标记
# 或者是子环境的一部分
# 或者全局typings命令不可用的时候: 
typings install dt~mocha --global --save

# 从其他版本处安装typings定义(比如env或者npm). 
typings install env~atom --global --save
typings install npm~bluebird --save

# 使用该文件`typings/index.d.ts` (在`tsconfig.json`文件使用或者用 `///` 定义). 
cat typings/index.d.ts

报错内容

typings ERR! message Unable to connect to "https://raw.githubusercontent.com/Def
initelyTyped/DefinitelyTyped/a4a912a0cd1849fa7df0e5d909c8625fba04e49d/node/index
.d.ts"
typings ERR! caused by getaddrinfo ENOENT raw.githubusercontent.com
typings ERR!
typings ERR! cwd C:\Users\user\Desktop\Embedded\rewi_blog\vuepress-rewi
typings ERR! system Windows_NT 10.0.19043
typings ERR! command "D:\\nodejs\\node.exe" "C:\\Users\\user\\AppData\\Roaming\\
npm\\node_modules\\typings\\dist\\bin.js" "install" "dt~node" "--global" "--save
"
typings ERR! node -v v14.17.6
typings ERR! typings -v 2.1.1
typings ERR! code EUNAVAILABLE
typings ERR!
typings ERR! If you need help, you may report this error at:
typings ERR!   <https://github.com/typings/typings/issues>

解决办法

  1. .typingsrc 方法
  • 不成功
  1. 修改hosts文件

    参考:https://newsn.net/say/raw-githubusercontent-com.html

  • 利用 chinaz的ping功能,查找合适的ip:
    • chinaz: http://ping.chinaz.com/raw.githubusercontent.com

在这里插入图片描述

  • 打开hosts文件,把IP粘贴:
    在这里插入图片描述
  • 成功,出现了一个ytpings文件
    在这里插入图片描述
### 关于 Vue3 中使用 `motion-v` 出现错误的解决方案 在 Vue3 项目中使用 `motion-v` 可能会因为多种原因导致报错,例如依赖版本不匹配、未正确引入组件或者缺少必要的配置。以下是针对该问题的具体分析和解决方法: #### 1. **确认依赖版本** 确保项目的依赖项与 `motion-v` 的需求兼容。如果存在版本冲突,则可能导致运行时错误。可以通过以下命令检查当前安装的依赖版本: ```bash npm list vue motion-v ``` 如果发现版本不一致,建议卸载并重新安装指定版本的依赖包: ```bash npm uninstall motion-v npm install motion-v@latest --save ``` #### 2. **正确引入 `motion-v` 组件** 根据官方文档或社区指南,在 Vue3 项目中正确注册和使用 `motion-v` 提供的功能。通常情况下,需要在入口文件(如 `main.js` 或 `main.ts`)中完成初始化操作[^3]。 示例代码如下: ```javascript import { createApp } from 'vue'; import App from './App.vue'; // 引入 motion-v 并注册到全局 import MotionV from 'motion-v'; const app = createApp(App); app.use(MotionV); app.mount('#app'); ``` #### 3. **检查 TypeScript 配置(如有必要)** 如果项目基于 TypeScript 构建,可能需要额外调整类型声明文件以支持 `motion-v` 功能。具体做法是在 `shims-typings.d.ts` 文件中添加相关定义: ```typescript declare module 'motion-v' { const MotionV: any; export default MotionV; } ``` #### 4. **排查样式加载问题** 某些动画库依赖 CSS 加载器或其他预处理器工具链的支持。如果项目采用按需加载策略,务必验证是否存在遗漏的关键配置。例如,Ant Design Vue 的按需加载场景下曾因 Less 编译选项缺失而引发类似问题[^4]。因此,推荐尝试补充 Webpack/Vite 的自定义设置以适配 `motion-v` 的特殊需求。 对于 Vite 用户来说,可以在 `vite.config.js` 添加以下片段: ```javascript export default defineConfig({ css: { preprocessorOptions: { less: { javascriptEnabled: true, }, }, }, }); ``` 而对于传统 Webpack 流程而言,修改方式略有不同: ```javascript module.exports = { css: { loaderOptions: { less: { javascriptEnabled: true, }, }, }, }; ``` --- ### 总结 上述措施涵盖了从基础环境搭建至高级定制化的多个层面,能够有效缓解大部分由 `motion-v` 导致的技术难题。然而实际开发过程中仍需结合具体情况灵活应对。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值