我在打包时遇到问题 my TypeScript project我已在 npm registry 上发布。我不熟悉打包模块供其他人使用,所以我可能只是做错了什么。
这些是 package.json 的部分这似乎相关:
{
"name": "robotnik-bot",
"version": "0.1.0-4",
"description": "Friendly neighborhood Discord bot",
"main": "out/index",
"types": "out/index.d.ts",
"typings:": "out/index.d.ts",
"scripts": {
"build": "tsc",
"test": "mocha -r ts-node/register tests/**/*.test.ts",
"coverage": "nyc -r lcov -e .ts -x \"*.test.ts\" npm run test",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"prepublish": "tsc"
},
这是 tsconfig.json :
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "out",
"sourceRoot" : "src",
"sourceMap": true,
"declaration": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"moduleResolution": "node",
"typeRoots": [
"node_modules/@types"
]
},
"exclude": [
"out",
"nodule_modules",
"tests"
],
"lib": ["es2015"],
}
在我的依赖项目中,我已将包添加为依赖项并尝试使用它:
"dependencies": {
"robotnik-bot": "^0.1.0-4"
},
"devDependencies": {
"typescript": "^3.8.2"
},
"scripts": {
"start" : "tsc && node dist/index.js"
}
import { Builder } from 'robotnik-bot';
const bot = new Builder().build();
但是依赖的项目找不到该模块。当我检查 nodue_modules 时,它似乎刚刚将我的项目文件结构与 TypeScript 源打包在一起;不应该有一些已编译的Javascript吗?
最佳答案
应该有编译好的文件。如果没有,您要么发布一个干净的工作目录(没有编译的文件),要么您的打包配置为不包含编译的文件。
您可以使用npmpublish --dry-run
来查看将包含哪些内容。
请注意以下事项 from the documentation :
Publishes a package to the registry so that it can be installed by name. All files in the package directory are included if no local
.gitignore
or.npmignore
file exists. If both files exist and a file is ignored by.gitignore
but not by.npmignore
then it will be included
您的文件似乎通过 .gitignore
被排除,这是有道理的。您可以使用 package.json
中的 files
属性将它们添加回来,例如
"files": [
"out"
]
关于javascript - 我的应用程序找不到从 NPM 注册表下载的 TypeScript 包(未找到模块),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61205804/