Closed linxingwu closed 4 years ago
import Koa from "koa" import Router from "koa-router" import logger from "koa-logger" import json from "koa-json" const app = new Koa() const router = new Router() router.get("/",async(ctx: any,next: any)=>{ ctx.body = { meg:"Hello world" } await next }) app.use(logger()) app.use(json()) app.use(router.routes()).use(router.allowedMethods()) app.listen(3000,()=>console.log("app is running at 3000"))
Here is my package.json
{ "name": "babel-typescript-sample", "version": "0.7.2", "license": "MIT", "scripts": { "type-check": "tsc --noEmit", "type-check:watch": "npm run type-check -- --watch", "build": "npm run build:types && npm run build:js", "build:types": "tsc --emitDeclarationOnly", "build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline" }, "devDependencies": { "@babel/cli": "^7.8.3", "@babel/core": "^7.8.3", "@babel/plugin-proposal-class-properties": "^7.8.3", "@babel/preset-env": "^7.8.3", "@babel/preset-typescript": "^7.8.3", "@types/koa": "^2.11.3", "typescript": "^3.7.5" }, "dependencies": { "koa": "^2.11.0", "koa-bodyparser": "^4.3.0", "koa-json": "^2.0.2", "koa-logger": "^3.2.1", "koa-router": "^8.0.8" } }
my file structure loos like:
/------- -lib -index.js -index.d.ts -node_modules -src -index.ts
npm run build
src/index.ts:2:20 - error TS2307: Cannot find module 'koa-router'.
There are the same reason, could find declare file just run npm npm i @types/<package>
could find declare file
npm i @types/<package>
Here is my package.json
my file structure loos like:
npm run build
,I got errorsrc/index.ts:2:20 - error TS2307: Cannot find module 'koa-router'.
I write 'koa-router.d.ts' myself, but I don't think it's a great idea, How do you guys resolve?