#node.js #docker
Вопрос:
app2_1 | /usr/src/app/validations/validators.js:3
app2_1 | exports.hasName = params("Name")
app2_1 | ^
app2_1 |
app2_1 | TypeError: params is not a function
app2_1 | at Object.<anonymous> (/usr/src/app/validations/validators.js:3:18)
app2_1 | at Module._compile (internal/modules/cjs/loader.js:778:30)
app2_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
app2_1 | at Module.load (internal/modules/cjs/loader.js:653:32)
app2_1 | at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
app2_1 | at Function.Module._load (internal/modules/cjs/loader.js:585:3)
app2_1 | at Module.require (internal/modules/cjs/loader.js:692:17)
app2_1 | at require (internal/modules/cjs/helpers.js:25:18)
app2_1 | at Object.<anonymous> (/usr/src/app/routes/badge.js:3:18)
app2_1 | at Module._compile (internal/modules/cjs/loader.js:778:30)
app2_1 | [nodemon] app crashed - waiting for file changes before starting...
app1_1 | /usr/src/app/validations/validators.js:3
app1_1 | exports.hasName = params("Name")
app1_1 | ^
app1_1 |
Не знаю, почему разбился nodemon. Это сработало до того, как я изменил свой файл docker-compose.
const {params} = require('express-validator');
exports.hasName = params("Name")
.isLength({min: 2})
.withMessage("Name is required. Min Length 2 characters");
Это файл, в котором появляется ошибка. Не знаю, что может быть не так.
Это мой файл package.json:
{
"name": "webapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon app.js",
"start:prod": "node app.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-validator": "^6.12.1",
"fs": "0.0.1-security",
"https": "^1.0.0",
},
"devDependencies": {
"nodemon": "^2.0.12"
}
}
Я думаю, что это может быть из-за моего док-файла, я настраиваю два этапа:
#first stage
FROM node:10-alpine as builder
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}
RUN apk --no-cache add python make g
COPY package*.json ./
RUN npm install
#second stage
FROM node:10-alpine
WORKDIR /usr/src/app
COPY --from=builder node_modules node_modules
COPY . .
CMD [ "npm", "run", "start:prod" ]
Not sure if I should remove the second stage and put the CMD command above. I did remove the first stage, and then ran: docker-compose down —rmi all
However, it doesn’t work.