express 代码“const app = express()”不起作用!!
** 嗨,我这里有一些问题!我的控制台返回此错误,但我遵循最好的方法!请某人
给我一盏灯。
server.js 存档:
import * as express from "express";
import * as mongoose from "mongoose";
//inciando o app
const app = express();
//iniciando o banco de dados
mongoose.connection('mongodb://localhost:27017/program01', {useNewUrlParser: true});
//primeira rota
app.get('/',(req,res)=>{
res.send('Hello World')
})
app.listen(3000)
==============================
console:
*[nodemon] restarting due to changes...
[nodemon] starting `node server.js`
[nodemon] restarting due to changes...
(node:12020) ExperimentalWarning: The ESM module loader is experimental.
[nodemon] starting `node server.js`
(node:8472) ExperimentalWarning: The ESM module loader is experimental.
file:///C:/Users/USUARIO/Documents/Project%20Web/program01/server.js:4
const app = express();
^
TypeError: express is not a function
at file:///C:/Users/USUARIO/Documents/Project%20Web/program01/server.js:4:13
at ModuleJob.run (internal/modules/esm/module_job.js:137:37)
at async Loader.import (internal/modules/esm/loader.js:179:24)
[nodemon] app crashed - waiting for file changes before starting...* ```
another's archives :
**node_modules**
**package.json**
**package-lock.json**
**yarn-error.log**
最佳答案
您需要对 express
使用默认导入, IE。
import express from 'express';
代替import * as express from 'express';
关于javascript - 类型错误 : express is not a function -,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62522062/