打字稿/节点无法解析模块路径

时间:2018-02-20 02:04:37

标签: node.js typescript express

我对Express和Typescript都是全新的。我有继承一个使用express for API的项目。我需要做一些更改,但要开始,我甚至无法转换代码。在转向SO之前,我一直在试图寻找解决方案,但我在这里,所以请善待。

当我跑步时:

  

npm run tsc

我收到了许多与查找包相关的错误消息:

app/server.ts(2,26): error TS2307: Cannot find module 'express'.
app/server.ts(11,20): error TS2304: Cannot find name 'Promise'.
app/server.ts(30,22): error TS2304: Cannot find name 'require'.

这是我的package.json

{
"name": "my-backend",
  "version": "1.0.0",
  "description": "Express backend",
  "scripts": {
	"start": "node dist/server.js",
	"tsc": "tsc",
	"typings": "typings"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
	"body-parser": "^1.15.2",
	"cors": "^2.7.1",
	"express": "^4.14.0",
	"indicative": "^2.1.2",
	"jsonwebtoken": "^7.1.6",
	"lodash": "^4.16.1",
	"moment": "^2.17.1",
	"mongodb": "^2.2.1",
	"mongoose": "^4.5.4",
	"morgan": "^1.7.0",
	"node-uuid": "^1.4.8",
	"validator": "^5.5.0"
  },
  "repository": {},
  "devDependencies": {
	"tslint": "^3.11.0",
	"typescript": "^1.8.10",
	"typings": "^1.3.0"
  }
}

这是我的tsconfig.js

{
    "compileOnSave": true,
    "compilerOptions": {
        "target": "es5",
        "declaration": false,
        "module": "commonjs",
        "moduleResolution": "classic",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false,
        "suppressImplicitAnyIndexErrors": true,
        "outDir": "dist/"
    },
    "exclude": [
        "node_modules"
    ]
}

我安装了所有正在运行的软件包:

  

npm install

NPM日志包含以下错误:

9 verbose lifecycle my-backend@1.0.0~tsc: CWD: C:\Source\ExpressBackEnd
10 silly lifecycle my-backend@1.0.0~tsc: Args: [ '/d /s /c', 'tsc' ]
11 silly lifecycle my-backend@1.0.0~tsc: Returned: code: 2  signal: null
12 info lifecycle my-backend@1.0.0~tsc: Failed to exec tsc script
13 verbose stack Error: my-backend@1.0.0 tsc: `tsc`
13 verbose stack Exit status 2
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:285:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid my-backend@1.0.0

非常感谢任何指针/所需的阅读。

1 个答案:

答案 0 :(得分:0)

我的朋友你需要安装打字稿定义文件。示例:@ types / node,@ types / express ...

<video width="600" controls="controls"> <source src="{{ site.my-media-path }}/myvideo.mp4"> </video>