自定义npm包leon-theme导入遇ts(2307)错误:无法找到模块或类型声明
问题:导入自定义npm包时出现TypeScript模块未找到错误
我开发了一个自定义npm包,之后创建了一个基础的create-react-app项目,尝试在项目的src/index.tsx文件中导入该包。添加导入语句import { LeonTheme } from "leon-theme";后,鼠标悬停在该行时出现以下错误:
Cannot find module 'leon-theme' or its corresponding type declarations.ts(2307)
自定义npm包的tsconfig配置
{ "compilerOptions": { "module": "ES6", "target": "es2016", "lib": ["ES2020", "DOM"], "jsx": "react", "allowJs": true, "declaration": true, "declarationDir": "types", "sourceMap": true, "allowSyntheticDefaultImports": true, "noEmit": false, "outDir": "./dist", "moduleResolution": "node", "noImplicitAny": false }, "include": ["src/**/*.ts"] }
自定义npm包的package.json配置
{ "name": "leon-theme", "version": "0.0.15", "module": "dist/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" ], "types": "dist/index.d.ts" }
测试项目node_modules中leon-theme的目录结构

内容的提问来源于stack exchange,提问作者Leon Gaban
相关产品推荐
相关产品推荐

