我在项目中本地安装了bower,在其中创建了一个文件夹'node_modules'和'bower'.然后我在命令行上运行bower:
$ bower
bower: ??????? ?? ??????? (command not found)
Run Code Online (Sandbox Code Playgroud)
为什么是这样?如果我安装bower全局一切正常.
我在tsconfig.json文件中设置属性路径,如:
"paths": {
"*": [
"*",
"src/*",
"node_modules/*"
],
"src/*": [ "./src/*" ]
},
Run Code Online (Sandbox Code Playgroud)
它让我能够更轻松地采取一些模块:例如
- src
|- moduleA
|- utils
|- moduleB
// moduleA
import { something } from 'utils/moduleB'
Run Code Online (Sandbox Code Playgroud)
但是在编译之后我得到了moduleB.js中的下一个路径:
something = require('utils/moduleB')
Run Code Online (Sandbox Code Playgroud)
而不是相对路径:
something = require('./utils/moduleB')
Run Code Online (Sandbox Code Playgroud)
它在Node下不起作用,因为Node模块解析系统对utils文件夹一无所知.
那么,我如何强制tsc在这里使用相对路径?
更新:这是我生成的js文件的真实示例:
data&utils它们是内部模块而非外部模块.我的问题是为什么tsc不能根据编译文件中的baseUrl解析它们
我为这样的用户创建了一个模式:
var schema = new Schema({
username: {
type: String,
unique: true,
required: true
},
hashedPassword: {
type: String,
required: true
},
salt: {
type: String,
required: true
}
});
schema.virtual('password')
.set(function(password) {
this._plainPassword = password;
this.salt = Math.random() + '';
this.hashedPassword = this.encryptPassword(password);
})
.get(function() { return this._plainPassword; });
schema.methods.encryptPassword = function(password) {
return crypto.createHmac('sha1', this.salt).update(password).digest('hex');
};
Run Code Online (Sandbox Code Playgroud)
然后我试图使用两种方法更改密码:
工作很好
User.findById('userId ..',function(err,user){user.password ='456'; user.save(cb);})
为什么这种方法不起作用?
User.findByIdAndUpdate('userId',{$ set:{password:'456'}},cb)