npm build跟types有什么关系?

我写了一个lib库,package.json中定义了一些配置

{
    "main": "/dist/index.umd.js",
     "module": "/dist/index.mjs",
     "types": "/dist/index.d.ts",    
    "scripts": {
        "build": "vite build"
      }
}

我需要执行build命令把代码编译到dist,再去发布,但是一开始dist是空文件夹,每次执行build命令,都会报错,说没有dist/index.d.ts

✓ built in 268ms
error during build:
Error: ENOENT: no such file or directory, open '/dist/index.d.ts'

我如何设置build的时候不关联这个types字段。

阅读 1.7k
1 个回答

types作用是指定 TypeScript 的类型定义的入口文件,
你设置相对路径看看
"types": "./dist/index.d.ts", 或者入口文件名不对?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题