npm build跟types有什么关系?

作者站长头像
站长
· 阅读数 8

我写了一个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个回答
avatar
test
2024-07-05

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

回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容