在node_modules中我找不到“验证程序”包,但是我不明白为什么它没有与dockerfile一起安装在npm中。 这是我的项目。
DockerFiles
import React, { Component } from 'react';
export default class Create extends Component {
constructor(props) {
super(props);
this.onChangeFirstname = this.onChangeFirstname.bind(this);
this.onChangeLastname = this.onChangeLastname.bind(this);
this.onChangeMessage = this.onChangeMessage.bind(this);
this.onSubmit = this.onSubmit.bind(this);
this.state = {
person_firstname: '',
person_lastname: '',
message:''
}
}
onChangeFirstname(e) {
this.setState({
person_firstname: e.target.value
});
}
onChangeLastname(e) {
this.setState({
person_lastname: e.target.value
})
}
onChangeMessage(e) {
this.setState({
message: e.target.value
})
}
onSubmit(e) {
e.preventDefault();
console.log(`The values are ${this.state.person_firstname}, ${this.state.person_lastname}, and ${this.state.message}`)
this.setState({
person_firstname: '',
person_lastname: '',
message: ''
})
}
render() {
return (
<div style={{marginTop: 10}}>
<h3>Contact Form</h3>
<form onSubmit={this.onSubmit}>
<div className="form-group">
<label>First Name: </label>
<input type="text" className="form-control"
onChange={this.onChangeFirstName}/>
</div>
<div className="form-group">
<label>Last Name: </label>
<input type="text" className="form-control"
onChange={this.onChangeLastname}/>
</div>
<div className="form-group">
<label>Message: </label>
<textarea className="form-control"
onChange={this.onChangeMessage}>
</textarea>
</div>
<div className="form-group">
<input type="submit" value="Submit" className="btn btn-primary"/>
</div>
</form>
</div>
)
}
}
package.json
FROM node:latest
WORKDIR /app
ADD restapi/* /app/
RUN npm install -g nodemon && \
npm install -g
RUN npm install -g validator
EXPOSE 3000
CMD ["nodemon"]
docker-compose
"dependencies": {
"body-parser": "^1.18.3",
"cookie-parser": "^1.4.4",
"debug": "^4.1.1",
"express": "^4.16.4",
"firebase-admin": "^7.0.0",
"jade": "^1.11.0",
"kafka-node": "^4.0.2",
"mongoose": "^5.4.18",
"mongoose-float": "^1.0.3",
"morgan": "^1.9.1",
"bcryptjs": "^2.4.3",
"jsonwebtoken": "^8.1.0",
"validator": "^12.1.0"
}
docker-compose返回此错误:
version: "3"
services:
mongodb:
image: mongo:latest
container_name: mongo1
ports:
- 27017:27017
restapi:
build: .
image: restapi
container_name: restapi1
depends_on:
- mongodb
volumes:
- //c/Users/Halnap/restapi_project/restapi:/app
ports:
- 3000:3000
也许我应该在package-lock.json中添加验证器? 在package-lock.json中缺少验证器和bcryptjs(已从dockerfiles中删除)中,为什么不与npm一起添加? 在执行过程中,它是根据Powershell + Validator@12.1.0的屏幕添加的 在0.739秒内添加了2位贡献者的1个程序包
答案 0 :(得分:0)
在DockerFiles中,validator
软件包正在全局安装,而不是在当前目录中安装。在以下命令中可以看到:npm install -g validator
。您可以看到nodemon
也在全局安装,也没有出现在依赖项的package.json
列表中。
如果要在本地安装此软件包,请运行npm i -S validator
。