我看到了一些关于这个问题的问题,但没有一个不起作用我有一个nodejs项目和Typescript。我不喜欢使用相对路径。当我在 tsconfig 中设置路径时,出现以下错误:
找不到模块“@app/controllers/main”
// main.ts
export const fullName = "xxxx";
...
// app.ts
import { fullName } from '@app/controllers/main'
...
Run Code Online (Sandbox Code Playgroud)
这是我的项目的结构:
-node_modules
-src
----controllers
---------------main.ts
----app.ts
-package.json
-tsconfig.json
Run Code Online (Sandbox Code Playgroud)
ts配置:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"baseUrl": ".",
"paths": {
"@app/*": ["src/*"]
},
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题出在哪里?
提前致谢。
安装后winston-mongodb我收到以下警告:
(node:9316) 弃用警告:当前的服务器发现和监控引擎已弃用,并将在未来版本中删除。要使用新的服务器发现和监控引擎,请将选项 { useUnifiedTopology: true } 传递给 MongoClient 构造函数。
这是我的 app.js :
require('express-async-errors');
const express = require('express'),
config = require('config'),
morgan = require('morgan'),
helmet = require('helmet'),
winston = require('winston'),
mongoose = require('mongoose');
require('winston-mongodb');
mongoose.connect("mongodb://localhost:27017/wsep",
{ useNewUrlParser: true, useFindAndModify: false, useCreateIndex: true, useUnifiedTopology: true })
.then(connect => { console.log("connected to mongo db...") })
.catch(error => { console.log("could not connect to mongo db ...") })
winston.add(new winston.transports.MongoDB({
db: 'mongodb://localhost:27017/wsep'
}));
Run Code Online (Sandbox Code Playgroud)
如果我删除/评论以下片段代码,上面的警告将消失:
winston.add(new winston.transports.MongoDB({
db: 'mongodb://localhost:27017/wsep'
}));
Run Code Online (Sandbox Code Playgroud)
编辑:
包.json
{ …Run Code Online (Sandbox Code Playgroud)