我正在构建一个打字稿模块,我将在节点服务器和angular2应用程序之间共享,但要求似乎无法在安装后找到它。这是我的共享模块
的package.json
{
"name": "MyCommonLibrary",
"version": "0.0.1",
"description": "",
"main": "bin/index.js",
"scripts": {
},
"license": "ISC",
"devDependencies": {
"typescript": "^1.8.9",
"typings": "^0.7.9"
}
}
tsconfig.json
{
"compilerOptions":{
"target":"es5",
"module":"commonjs",
"declaration":true,
"sourceMap":true,
"sourceRoot":"src",
"outDir":"bin"
},
"exclude":[
"node_modules",
"bin",
"typings/main",
"typings/main.d.ts"
]
}
的src / index.ts
export class TestClass {
name:string;
constructor(name:string){
this.name = name;
}
}
一切似乎都正常编译,我的bin / index.js看起来不错。 我跑
" npm install ../MyCommonLibrary --save"
从服务器项目和模块安装正确。但是当我尝试编译时,我得到一个错误,
无法找到模块' MyCommonLibrary'
即使MyCommonLibrary存在于node_modules目录中,并且似乎拥有所有正确的信息
server.ts
import express = require('express');
import myCommonLibrary = require('MyCommonLibrary');
var app = express();
app.get('/',function(req,res){
res.send('Hello World');
})
var server = app.listen(3000,function(){
var host:string = server.address().address;
var port:number = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
任何见解都将受到赞赏
编辑:经过大量挖掘后,我找到了解决方案!从this example我发现添加了
"分型":"箱/索引",
我的package.json修复了这个问题,即使Atom Typescript插件仍然抱怨,tsc编译得很好。