[英]Typescript / node unable to resolve module paths
I've completely new to both Express and Typescript. 我对Express和Typescript都是全新的。 I have inherited a project that is using express for an API.
我继承了一个将Express用于API的项目。 I need to make some changes, but to get started, I can't even transpile the code.
我需要进行一些更改,但是要开始使用,我什至无法翻译代码。 I have been racking my brain trying to find a solution before turning to SO, but here I am, so please be kind.
在寻求SO解决方案之前,我一直在绞尽脑汁尝试寻找解决方案,但是我来了,所以请保持友好。
When I run: 当我跑步时:
npm run tsc
npm运行tsc
I get dozens of error messages that appear related to finding packages: 我收到许多与查找软件包有关的错误消息:
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'.
Here is my package.json 这是我的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" } }
Here's my tsconfig.js 这是我的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" ] }
I've installed all the packages running: 我已经安装了所有正在运行的软件包:
npm install
npm安装
The NPM log includes the following error: 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
Any pointers / required reading is greatly appreciated. 任何指针/所需的阅读,不胜感激。
My friend you need to install typescript definition files. 我的朋友,您需要安装打字稿定义文件。 Example: @types/node, @types/express ...
例如:@ types / node,@ types / express ...
npm install @types/node @types/express -D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.