我创建了一个简单的打字稿项目来导出ENUMS,我成功地编译了该项目。 tsconfig.json和package.json如下。 我使用npm命令打包它,并且npm也发布它。我将相同的软件包安装到新项目中,并使用代码
导入相同的软件包import Numbers = require('@hk18/export/dist');
我想变得像
import Numbers = require('@hk18/export');
为什么包中包含dest文件夹?
{ "compilerOptions": {
"module": "commonjs",
"target": "es5",
"outDir": "./dist",
"moduleResolution": "node",
"declaration": true }, "include": [
"src/**/*.ts",
"index.ts" ] }
___________________________________________________________
{ "name": "@hk18/export", "version": "2.0.0", "description": "test project to create npm package", "main": "index.js", "scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"lint": "tslint --project \"./tsconfig.json\"",
"test": "mocha --reporter spec",
"docs": "typedoc --out docs src",
"gh-pages": "rimraf docs && npm run docs && gh-pages -d docs" }, "author": "HK", "license": "ISC", }
答案 0 :(得分:0)
您的package.json is missing a types
entry。它应该与您的main
条目匹配。同样,您的主体也应该指向dist
文件夹。
"main": "./dist/index.js",
"types" : "./dist/index.d.ts",