找不到模块“vue-router”。你的意思是要将 "moduleResolution" 选项设置为 "node",还是要将别名添加到 "paths" 选项中?ts(2792)\
时间: 2023-08-06 19:03:39 浏览: 279
引用\[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 ]
阅读全文