我有下面的 index.ts
index.ts
import { User } from "./datatypes" import express from 'express'; console.log("hello world")
这是我的 package.json
package.json
{ "name": "simple_app", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "tsc index.ts && node index.js" "keywords": [], "author": "", "license": "ISC", "dependencies": { "dotenv": "^16.0.0", "express": "^4.17.3" "devDependencies": { "@types/express": "^4.17.13", "@types/node": "^17.0.23", "ts-node": "^10.7.0", "typescript": "^4.6.3" }
这是我的tsconfig.json:
{ "compilerOptions": { "module": "commonjs", "esModuleInterop": true, "resolveJsonModule": true, "target": "es6", "moduleResolution": "node", "sourceMap": true, "outDir": "dist" "lib": ["es2015"] }
当我编写 npm run start 时,我获得:
npm run start
Module '"/mnt/c/Users/raffa/Desktop/simple_app/node_modules/@types/express/index"' can only be default-imported using the 'esModuleInterop' flag 2 import express from 'express';