找不到模块“vue”。你的意思是要将 "moduleResolution" 选项设置为 "node",还是要将别名添加到 "paths" 选项中?
时间: 2024-04-15 10:21:32 浏览: 20
根据提供的引用内容,当出现找不到模块"vue"的错误时,可以尝试以下两种解决方法:
1. 将"moduleResolution"选项设置为"node":这个选项用于指定模块解析的策略。将其设置为"node"可以让TypeScript使用Node.js的模块解析方式来查找模块。你可以在tsconfig.json文件中添加以下配置:
```json
{
"compilerOptions": {
"moduleResolution": "node"
}
}
```
2. 将别名添加到"paths"选项中:这个选项用于指定模块的别名路径。你可以在tsconfig.json文件中添加以下配置:
```json
{
"compilerOptions": {
"paths": {
"vue": ["node_modules/vue/dist/vue.js"]
}
}
}
```
请注意,以上两种方法可以根据具体情况选择其中一种或同时使用。根据你的需求和项目配置,你可以尝试这两种方法来解决找不到模块"vue"的问题。
相关问题
找不到模块“vue-router”。你的意思是要将 "moduleResolution" 选项设置为 "node",还是要将别名添加到 "paths" 选项中?ts(2792)
这个错误提示是在 TypeScript 中出现的,意思是找不到名为“vue-router”的模块。这可能是由于你的项目中缺少 Vue Router 模块或者配置有误导致的。
解决这个问题的方法是:
1. 确认你的项目中已经安装了 Vue Router 模块,可以使用命令 `npm install vue-router` 或者 `yarn add vue-router` 来安装。
2. 确认在你的 TypeScript 配置文件中,`moduleResolution` 选项已经设置为 `'node'`。这个选项告诉 TypeScript 如何解析模块名称,应该设置为 `'node'`。
3. 如果你的项目中使用了别名,需要将别名添加到 `paths` 选项中。例如,如果你在 `tsconfig.json` 中定义了以下别名:
```json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}
```
那么在引入 Vue Router 模块时,应该使用别名路径:
```typescript
import VueRouter from '@/router'
```
注意,这里的 `'@'` 符号是别名,实际对应的是 `src/` 目录。
希望这些方法能够帮助你解决问题!
找不到模块“vue-router”。你的意思是要将 "moduleResolution" 选项设置为 "node",还是要将别名添加到 "paths" 选项中?ts(2792)\
引用\[1\]:在搭建ts的项目时,提示引入模块报错,找不到模块“@ant-design/pro-components”。你的意思是要将 "moduleResolution" 选项设置为 "node",还是要将别名添加到 "paths" 选项中? 虽然不会影响页面正常运行,但是对代码强迫症来说很难受 。\[1\]引用\[2\]:这里说的commonjs选项是指tsconfig.json文件中"module"属性 解决方案二: tsconfig.json文件 "paths": { "vuex": \["node_modules/vuex/types/index.d.ts"\] "vue-router": \["node_modules/........"\] } 。\[2\]引用\[3\]:2,找不到ts文件就更正常了,我们需要在tsconfig.json里面进行配置(没有的话就新建一个,在根src同级的目录下面)。就直接复制就完事了, { "compilerOptions": { "target": "esnext", "module": "esnext", "useDefineForClassFields": true, "moduleResolution": "node", "strict": true, "jsx": "preserve", "sourceMap": true, "skipLibCheck": true, "resolveJsonModule": true, "esModuleInterop": true, "lib": \["esnext", "dom"\], "baseUrl": "./", "paths": { "@": \["src"\], "@/*": \["src/*"\] } }, "include": \[ "src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "*.ts" \], "references": \[{ "path": "./tsconfig.node.json" }\] } 。\[3\]
问题:找不到模块“vue-router”。你的意思是要将 "moduleResolution" 选项设置为 "node",还是要将别名添加到 "paths" 选项中?ts(2792)
回答: 根据引用\[2\]中的解决方案二,你可以在tsconfig.json文件中的"paths"选项中添加别名来解决找不到模块的问题。具体做法是在"paths"中添加对应的别名和路径,例如:"vue-router": \["node_modules/........"\]。这样就可以正确引入"vue-router"模块了。
#### 引用[.reference_title]
- *1* [你的意思是要将 “moduleResolution“ 选项设置为 “node“,还是要将别名添加到 “paths“ 选项(已解决)](https://blog.csdn.net/weixin_49453320/article/details/130802958)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [typescript找不到模块‘vue‘ ‘vue-router](https://blog.csdn.net/qq_57423665/article/details/131348859)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [vue3引入.vue文件以及.ts文件时提示找不到模块](https://blog.csdn.net/qq_40606563/article/details/126068678)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)