相关疑难解决方法(0)

语法错误:不能在没有模块的情况下使用导入语句,类型错误 [ERR_UNKNOWN_FILE_EXTENSION]:Catch 22

我一直遇到节点 js 的问题。

这是相关代码(app.ts):

const express = require("express");
const auth = require("./service/auth");

import { Request, Response } from "express";

import User from "./model/User";
import con from "./config/db";

const port = 3000;

const app = express();

app.use(express.json());
...
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

(node:16524) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
C:\Users\010bo\OneDrive\Documents\GitHub\rpg-backend\app\app.ts:4
import { Request, Response } from "express";
^^^^^^

SyntaxError: Cannot …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript

5
推荐指数
1
解决办法
1182
查看次数

标签 统计

javascript ×1

node.js ×1

typescript ×1