我试图用typescriptNodeJS制作一个简单的API,但当我运行代码时,我遇到了这个错误

"此模块是使用‘export=’声明的,只能使用."

这是我的代码:

    {
  "name": "API-Proyecto",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "jsonwebtoken": "^8.5.1"
  },
  "devDependencies": {
    "@types/cors": "^2.8.6",
    "@types/express": "^4.17.6",
    "nodemon": "^2.0.4"
  }
}

指数ts

    import express from 'express';
import { Request, Response }  from 'express';
import cors from 'cors';

const app = express();

app.use(express.urlencoded({extended: true}));
app.use(express.json);
app.use(cors({origin: true, credentials: true}));

app.get('/api/auth/testing', (req: Request, res: Response) =>{
    res.status(200).json({
        ok : true,
        msg : 'hi from my method'
    });
});

app.listen(3000, () => {console.log('Server running on 3000' )});

tsconfig.json

    {
  "compilerOptions": {
    "target": "es6",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    "outDir": "./dist",                        /* Redirect output structure to the directory. */
    "esModuleInterop": true,                  /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
  }
}

推荐答案

你的代码很好.

Fix

当你需要重新启动你的代码时?

Typescript相关问答推荐

如何使打包和拆包功能通用?

从接口创建类型安全的嵌套 struct

为什么ESLint抱怨通用对象类型?

APP_INITIALIZER—TypeError:appInits不是函数

基于平台的重定向,Angular 为16

如何推断计算逻辑的类型

如何在TypeScrip中从字符串联合类型中省略%1值

向NextAuth会话添加除名称、图像和ID之外的更多详细信息

是否使用非显式名称隔离在对象属性上声明的接口的内部类型?

ANGLE独立组件布线错误:没有ActivatedRouting提供程序

函数重载中的不正确TS建议

为什么Typescript只在调用方提供显式泛型类型参数时推断此函数的返回类型?

是否可以强制静态方法将同一类型的对象返回其自己的类?

在TypeScript中扩展重载方法时出现问题

tailwind css未被应用-react

如何为特定参数定义子路由?

如何键入对象转换器

完全在类型系统中构建的东西意味着什么?

如何使用 runInInjectionContext 中的参数测试功能性路由防护

使用受保护的路由和入门来响应路由