【问题标题】:Cannot find module 'on-finished'找不到模块“完成”
【发布时间】:2016-12-07 01:01:09
【问题描述】:

我正在尝试运行节点服务器。我使用 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

我不知道问题出在哪里。如果我正在查看 node_modules 文件夹。模块存在。

问候

【问题讨论】:

    标签: javascript node.js express typescript


    【解决方案1】:

    你的问题是

    import * as express from "express";

    我使用 express 在我的应用程序上测试了完全相同的行,抛出了几乎相同的错误,因此你最好使用一个变量,就像我一直做的那样,它从来没有让我失望。

    var express = require('express')

    应该没有任何问题。

    【讨论】:

    • 我会在家里或工作时尝试。但是第一种方式是不是ECMA5方式? ...这很奇怪,为什么这不起作用...
    • 不知道,我一直使用变量来要求,我认为这是标准的。
    • 好的,我尝试了var express = require('express'),但它不起作用:/
    • 你现在遇到了什么问题?
    • 同样如此。我想我知道出了什么问题...当我使用 tsc 编译时,文件位于 cmpl 中。但是我的 .ts 需要的模块,比如 express 也没有移动到 cmpl ......仍然在 src/node_modules ......那我能做什么? ://
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-18
    • 2023-01-09
    • 2022-12-15
    • 1970-01-01
    • 2015-05-11
    • 2018-02-21
    • 2014-03-02
    相关资源
    最近更新 更多