nonzzz / vite-plugin-cdn

replace module with CDN. work with vite.
MIT License
73 stars 5 forks source link

1.0.0和1.1.0版本引入时ts报错 #43

Open ZhouZiXuan-imb opened 3 months ago

ZhouZiXuan-imb commented 3 months ago

感谢您的无私奉献 当我尝试使用1.1.0和1.0.0时我的ts类型报错Cannot find module 'vite-plugin-cdn2' or its corresponding type declarations.

image

降级到0.16.0后报错消失

我使用vite-plugin-cdn2/index 的引入方式ts类型报错消失

image

但是vite报错Cannot find module 'xxx/node_modules/vite-plugin-cdn2/index'

image
nonzzz commented 3 months ago

如果你降级到0.16.0 那么只需要'vite-plugin-cdn2' 即可 。你本地的typescript 版本是多少呢。

ZhouZiXuan-imb commented 3 months ago

如果你降级到0.16.0现在只需要'vite-plugin-cdn2'即可。你本地的typescript版本是多少呢。

我的ts版本为5.3.2

ZhouZiXuan-imb commented 3 months ago

如果你降级到0.16.0 那么只需要'vite-plugin-cdn2' 即可 。你本地的typescript 版本是多少呢。

当我尝试将ts版本降级为4.5.5时,还是同样的错误

image image
nonzzz commented 3 months ago

是否有全局安装typescript的情况呢? 能贴一下tsconfig吗

ZhouZiXuan-imb commented 3 months ago

我全局安装的ts版本为5.4.2,但这个问题可能跟我本地的ts版本关系不大。

image

以下是我的ts配置文件

tsconfig.json

{
  "references": [
    {
      "path": "./tsconfig.vite-config.json"
    },
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.vitest.json"
    }
  ],
  "files": []
}

tsconfig.app.json

{
  "extends": "@vue/tsconfig/tsconfig.web.json",
  "compilerOptions": {
    // "composite": true,
    "baseUrl": ".",
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  },
  "include": [
    "env.d.ts",
    "lib.d.ts",
    "src/**/*",
    "src/**/*.vue"
  ],
  "exclude": [
    "src/**/__tests__/*"
  ]
}

tsconfig.vite-config.json

{
  "extends": "@vue/tsconfig/tsconfig.node.json",
  "compilerOptions": {
    "composite": true,
    "types": ["node", "vitest"]
  },
  "include": ["vite.config.*"]
}

tsconfig.vitest.json

{
  "extends": "./tsconfig.app.json",
  "compilerOptions": {
    "composite": true,
    "lib": [],
    "types": ["node", "jsdom"]
  },
  "exclude": []
}
nonzzz commented 3 months ago

全局安装的typescript 在vscode 是会吃vscode本身的tsconfig 而你在项目里面配置了typescript 和tsconfig 这时候导致了vite.config.* 而vite config无法吃到ts config的配置。 因为 这个包指定了typesVersions 会发生一些重定向 你可以尝试手动设置项目指向到项目的typescript 或者 设置skipLibCheck

ZhouZiXuan-imb commented 3 months ago

我尝试在你的package.json中修改typesVersions,我添加了"./dist/index.d.ts",这对我起作用

image

typescript正常工作

image

你考虑在你的typesVersions中添加这段代码吗"./dist/index.d.ts"

ZhouZiXuan-imb commented 3 months ago

如果可以的话,我向你发起了一个pull request

nonzzz commented 3 months ago

Ok 我会在稍后验证。版本的发布会随着锈化以后进行发布。

ZhouZiXuan-imb commented 3 months ago

好的 再次感谢你的开源