Vue 中 ts 添加 fs 报错: Cannot find module ‘fs‘

Vue 中 ts 添加 fs 报错: Cannot find module 'fs'

1. 添加依赖

npm i --save-dev @types/node

2. 修改 tsconfig.json 配置文件

在这里插入图片描述

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "webpack-env",
      "mocha",
      "chai",
      "node"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ],
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

引用[1]:vue项目Error: Cannot find module ‘xxx’类报错的解决方法_晴天'的博客-CSDN博客_cannot find module vue 原文链接:https://blog.csdn.net/weixin_42216142/article/details/87191352 。 引用[2]:问题一:遇到报错信息 Error: Cannot find module ‘D:\project***\node_modules_@vue_cli-service@4.5.12@@vue\cli-service\bin\vue-cli-service.js’ 。 引用[3]:问题二:遇到报错信息 Module parse failed: Unexpected character ‘�’ (1:0) You may need an appropriate loader to handle this file type. (Source code omitted for this binary file) 问题一:处理方案 。 问题:Error: Cannot find module 回答: 当你在Vue项目中遇到"Error: Cannot find module"的报错信息时,这通常是由于缺少模块或路径错误导致的。[1]对于问题一中的报错信息"Error: Cannot find module ‘D:\project***\node_modules_@vue_cli-service@4.5.12@@vue\cli-service\bin\vue-cli-service.js’",可能是由于项目中缺少了vue-cli-service模块或者路径配置错误。解决方法可以尝试以下几步: 1. 确保你的项目中已经安装了vue-cli-service模块,可以通过运行命令"npm install @vue/cli-service"来安装。 2. 检查你的路径配置是否正确,确保路径指向正确的文件或模块。 3. 如果以上方法都没有解决问题,可以尝试删除node_modules文件夹并重新安装依赖,运行命令"npm install"。 对于问题二中的报错信息"Module parse failed: Unexpected character ‘�’ (1:0) You may need an appropriate loader to handle this file type. (Source code omitted for this binary file)",这通常是由于文件类型不被正确解析导致的。解决方法可以尝试以下几步: 1. 确保你的项目中已经安装了相应的loader,例如babel-loader或者file-loader,可以通过运行命令"npm install babel-loader"或者"npm install file-loader"来安装。 2. 检查你的webpack配置文件,确保loader的配置正确并且能够处理该文件类型。 3. 如果以上方法都没有解决问题,可以尝试更新相关loader的版本或者查找其他解决方案。 希望以上方法能够帮助你解决报错问题。如果问题仍然存在,请参考引用[1]中的原文链接获取更多详细的解决方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值