2016-08-01 176 views
1

我正在嘗試運行節點服務器。我使用Express和Typescript和VSCode作爲編輯器。如果我編譯並嘗試運行我的app.js我得到這個錯誤:找不到模塊'完成'

> Error: Cannot find module 'on-finished' 
>  at Function.Module._resolveFilename (module.js:440:15) 
>  at Function.Module._load (module.js:388:25) 
>  at Module.require (module.js:468:17) 
>  at require (internal/module.js:20:19) 
>  at Object.<anonymous> (C:\nodeProjects\node_modules\express\node_modules\finalhandler\index.js:16:18) 
>  at Module._compile (module.js:541:32) 
>  at Object.Module._extensions..js (module.js:550:10) 
>  at Module.load (module.js:458:32) 
>  at tryModuleLoad (module.js:417:12) 
>  at Function.Module._load (module.js:409:3) 

我app.ts:

/// <reference path="_all.d.ts" /> 
import * as express from "express"; 
var app = express(); 

app.get('/', function (req, res) { 
    res.send('Hello World!'); 
}); 

app.listen(3000, function() { 
    console.log('Listening on port 3000!'); 
}); 

我tsconfig:

{ 
    "version": "1.7.5", 
    "compilerOptions": { 
     "target": "es5", 
     "module": "commonjs", 
     "sourceMap": true, 
     "emitDecoratorMetadata": true, 
     "experimentalDecorators": true, 
     "outDir": "../cmpl" 
    } 
} 

我的項目結構:

- .vscode/ 
- cmpl/ 
- src/ 
-- node_modules/ 
-- public/ 
-- routes/ 
-- typings/ 
-- views/ 
-- _all.d.ts 
-- app.ts 
-- package.json 
-- tsonfig.json 

而且我不知道pro瑕疵是。如果我正在查看node_modules文件夾。該模塊存在。

格爾茨

回答

0

你的問題是

import * as express from "express";

我用快遞,幾乎摔同樣的錯誤測試完全相同的行上我的應用程序,所以你會更好使用一個變量,像我總是這樣做,而且我從來沒有失敗過。

var express = require('express')

應該沒有任何問題。

+0

我會嘗試,如果我在家裏或在工作。但第一種方法是ECMA5方式還是不行? ...這很奇怪,爲什麼這不起作用... – R3Tech

+0

不知道,我總是使用變量的要求,我相信是標準的。 – Cernodile

+0

好吧,我嘗試了'var express = require('express')'而且它不工作:/ – R3Tech