Javascript 包在项目中导入不正确
我最近创建了一个Typescript包,我想在NPM上发布之前在应用程序中测试它 条目文件(index.ts)如下所示=>Javascript 包在项目中导入不正确,javascript,typescript,npm,package,Javascript,Typescript,Npm,Package,我最近创建了一个Typescript包,我想在NPM上发布之前在应用程序中测试它 条目文件(index.ts)如下所示=> import Builder from './core/builder'; export default Builder; 基本上,有很多文件,但我希望用户只使用我在索引中导出的“静态”类Builder。因此,用户只需从“builderts”导入构建器即可。 我的package.json文件夹如下 "name": "builderts", "main": "./
import Builder from './core/builder';
export default Builder;
基本上,有很多文件,但我希望用户只使用我在索引中导出的“静态”类Builder
。因此,用户只需从“builderts”导入构建器即可。
我的package.json
文件夹如下
"name": "builderts",
"main": "./dist/builderts.js",
"types": "./dist/builderts.d.ts",
"files": [
"dist/*"
],
"scripts": {
"preversion" : "npm run lint",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"version" : "npm run format && git add -A src",
"postversion" : "git push && git push --tags",
"build": "tsc",
"watch": "tsc-watch",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
"lint": "eslint tsconfig.json"
},
我的tsconfig.json
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "amd", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
"outFile":"./dist/builderts.js", /* Concatenate and emit output to single file. */
"outDir": "dist", /* Redirect output structure to the directory. */
"strict": true, /* Enable all strict type-checking options. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
我面临的问题是,我试图创建一个小测试项目,并使用
npm安装绝对/path
它安装正确,但当我尝试使用
从“builderts”导入生成器代码>
我既没有自动补全功能,也没有自动补全功能
文件'D:/User/Local/gitRepo/builderts/dist/builderts.D.ts'不是模块
我不太明白我在这个过程中遗漏了什么。我认为您需要更新包.json中的类型
您在上面说过文件名是index.ts
,您是否考虑过更新package.json
{
...
"types": "./dist/index.ts",
...
}
如果检查节点\u模块
文件夹,是否看到构建器
项?您能否尝试卸载并使用npm-pack
(来自builderts)和npm-install
(在您的测试项目中)?通常,npm在本地软件包和符号链接方面存在著名问题。是否可以提供builderts.d.ts
文件(甚至部分文件)?可能是捆绑文件不是模块,因此无法从中导入某些内容。这个文件存在吗?index.ts
是应用程序的条目是的,但是当在/dist/builderts.d.ts
中构建它时,但是类型文件有问题,我检查了ts中的一些库,它们没有使用“声明”:true,