You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自定义npm包leon-theme发布后dist文件缺失,无法导入React项目

问题:npm包发布后dist文件缺失,导致React项目导入失败

我开发了leon-theme这个npm包,本地执行npm run build后,dist文件夹构建完全正常,但发布到npm之后,包里除了README和package.json之外,所有构建产物都不见了。在全新的React项目中导入该包时,直接提示找不到模块。

以下是相关配置:

tsconfig配置

{
  "compilerOptions": {
    "module": "ES6",
    "target": "es2016",
    "lib": ["ES2020", "DOM"],
    "jsx": "react",
    "declaration": true,
    "declarationDir": "types",
    "sourceMap": true,
    "allowSyntheticDefaultImports": true,
    "noEmit": false,
    "outDir": "./dist/lib/es6",
    "moduleResolution": "node"
  },
  "include": ["src/**/*"]
}

根目录package.json

{
  "name": "leon-theme",
  "version": "1.0.0",
  "module": "lib/es6/index.js",
  "description": "A simple React style & component library",
  "scripts": {
    "build": "rm -rf dist/lib && tsc --build"
  },
  "author": "Leon Gaban",
  "license": "ISC",
  "dependencies": {
    "react": "^18.2.0"
  },
  "devDependencies": {
    "@types/react": "^18.2.22",
    "jest-environment-jsdom": "^29.7.0",
    "tslib": "^2.6.2",
    "typescript": "^5.2.2"
  },
  "files": [
    "dist"
  ],
  "types": "dist/index/.d.ts"
}

dist目录下的package.json

{
  "name": "leon-theme",
  "version": "0.0.6",
  "module": "lib/es6/index.js",
  "description": "A simple React style & component library",
  "homepage": "https://github.com/leongaban/leon-theme",
  "bugs": {
    "url": "https://github.com/leongaban/leon-theme/issues"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/leongaban/leon-theme.git"
  },
  "keywords": [
    "javascript",
    "theme",
    "buttons",
    "leon"
  ],
  "scripts": {
    "build": "rm -rf dist/lib && tsc --build"
  },
  "author": "Leon Gaban",
  "license": "ISC",
  "dependencies": {
    "react": "^18.2.0"
  },
  "devDependencies": {
    "@types/react": "^18.2.22",
    "jest-environment-jsdom": "^29.7.0",
    "tslib": "^2.6.2",
    "typescript": "^5.2.2"
  },
  "files": [
    "dist"
  ],
  "types": "dist/index/.d.ts"
}

相关截图

内容的提问来源于stack exchange,提问作者Leon Gaban

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 08:18:23