错误:找不到“/config/config.json”。你有没有运行“续集初始化”?
Posted
技术标签:
【中文标题】错误:找不到“/config/config.json”。你有没有运行“续集初始化”?【英文标题】:ERROR: Cannot find "/config/config.json". Have you run "sequelize init"? 【发布时间】:2018-06-20 08:16:27 【问题描述】:我的 API 项目使用 Node.js - Express.js 有这个 Dockerfile
api.dockerfile
FROM node:9.3.0
COPY package.json ./
RUN npm set progress=false && npm config set depth 0 && npm cache clean --force
## Storing node modules on a separate layer will prevent unnecessary npm installs at each build
RUN npm i && npm install nodemon --save \
&& npm install pm2 -g \
&& npm install -g sequelize-cli \
&& mkdir /ng-app \
&& chown -R node:node /ng-app \
&& cp -R ./node_modules ./ng-app
# Migration
RUN sequelize db:migrate
RUN sequelize db:seed:all
USER node
WORKDIR /ng-app
COPY . .
RUN mv docker.env .env
CMD ["pm2-runtime", "index.js"]
docker-compose.yaml
version: "2"
services:
iproject-api:
build:
context: ./api
dockerfile: api.dockerfile
image: 'iproject-api'
ports:
- '3002:3002'
iproject-web:
build:
context: ./web
dockerfile: web.dockerfile
image: 'iproject-web:latest'
ports:
- '8080:8080'
links:
- iproject-api
这是结果,我得到了
**docker-compose build --no-cache**
Building iproject-api
Step 1/11 : FROM node:9.3.0
---> 3d1823068e39
Step 2/11 : COPY package.json ./
---> 68d259bbd036
Removing intermediate container 792b207a42ed
Step 3/11 : RUN npm set progress=false && npm config set depth 0 && npm cache clean --force
---> Running in ebd53a0f0e3d
npm WARN using --force I sure hope you know what you are doing.
---> cd598f62f4e5
Removing intermediate container ebd53a0f0e3d
Step 4/11 : RUN npm i && npm install nodemon --save && npm install pm2 -g && npm install -g sequelize-cli && mkdir /ng-app && chown -R node:node /ng-app && cp -R ./node_modules ./ng-app
---> Running in 492ea3c40c22
> bcrypt@1.0.3 install /node_modules/bcrypt
> node-pre-gyp install --fallback-to-build
node-pre-gyp ERR! Tried to download(404): https://github.com/kelektiv/node.bcrypt.js/releases/download/v1.0.3/bcrypt_lib-v1.0.3-node-v59-linux-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for bcrypt@1.0.3 and node@9.3.0 (node-v59 ABI) (falling back to source compile with node-gyp)
make: Entering directory '/node_modules/bcrypt/build'
CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o
CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt.o
CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt_node.o
In file included from ../../nan/nan.h:192:0,
from ../src/bcrypt_node.cc:1:
../../nan/nan_maybe_43_inl.h: In function 'Nan::Maybe<bool> Nan::ForceSet(v8::Local<v8::Object>, v8::Local<v8::Value>, v8::Local<v8::Value>, v8::PropertyAttribute)':
../../nan/nan_maybe_43_inl.h:112:73: warning: 'v8::Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>, v8::PropertyAttribute)' is deprecated (declared at /root/.node-gyp/9.3.0/include/node/v8.h:3114): Use CreateDataProperty / DefineOwnProperty [-Wdeprecated-declarations]
return obj->ForceSet(isolate->GetCurrentContext(), key, value, attribs);
^
SOLINK_MODULE(target) Release/obj.target/bcrypt_lib.node
COPY Release/bcrypt_lib.node
COPY /node_modules/bcrypt/lib/binding/bcrypt_lib.node
TOUCH Release/obj.target/action_after_build.stamp
make: Leaving directory '/node_modules/bcrypt/build'
npm notice created a lockfile as package-lock.json. You should commit this file.
added 259 packages in 9.9s
> nodemon@1.14.10 postinstall /node_modules/nodemon
> node -e "console.log('\u001b[32mLove nodemon? You can now support the project via the open collective:\u001b[22m\u001b[39m\n > \u001b[96m\u001b[1mhttps://opencollective.com/nodemon/donate\u001b[0m\n')" || exit 0
Love nodemon? You can now support the project via the open collective:
> https://opencollective.com/nodemon/donate
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted "os":"darwin","arch":"any" (current: "os":"linux","arch":"x64")
+ nodemon@1.14.10
added 246 packages in 7.093s
/usr/local/bin/pm2 -> /usr/local/lib/node_modules/pm2/bin/pm2
/usr/local/bin/pm2-dev -> /usr/local/lib/node_modules/pm2/bin/pm2-dev
/usr/local/bin/pm2-runtime -> /usr/local/lib/node_modules/pm2/bin/pm2-runtime
/usr/local/bin/pm2-docker -> /usr/local/lib/node_modules/pm2/bin/pm2-docker
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/pm2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted "os":"darwin","arch":"any" (current: "os":"linux","arch":"x64")
+ pm2@2.9.1
added 251 packages in 6.35s
/usr/local/bin/sequelize -> /usr/local/lib/node_modules/sequelize-cli/lib/sequelize
+ sequelize-cli@3.2.0
added 105 packages in 3.718s
---> 19c196ba636a
Removing intermediate container 492ea3c40c22
Step 5/11 : RUN sequelize db:migrate
---> Running in cc84d0fbfc57
Sequelize CLI [Node: 9.3.0, CLI: 3.2.0, ORM: 4.31.0]
WARNING: This version of Sequelize CLI is not fully compatible with Sequelize v4. https://github.com/sequelize/cli#sequelize-support
错误:找不到“/config/config.json”。你有没有运行“sequelize init”?
如何调试这个?
【问题讨论】:
【参考方案1】:sequelize
命令可能在当前工作目录中寻找config/config.json
。在您运行命令时,/
。您可能希望它以/ng-app
作为工作目录运行。为此,您只需将 WORKDIR /ng-app
移动到 sequalize
命令上方即可。
【讨论】:
【参考方案2】:您可以为您的项目的 Sequlize CLI 命令创建一个 .sequelizerc 配置文件,该命令告诉 Sequlize 在哪里查找配置文件。
var path = require('path')
module.exports =
'config': path.resolve('server', 'config', 'database.json'),
'migrations-path': path.resolve('server', 'migrations'),
'models-path': path.resolve('server', 'models'),
'seeders-path': path.resolve('server', 'seeders'),
【讨论】:
【参考方案3】:对于使用 docker-compose 的用户:请记住将 config
和 models
文件夹包含在 docker-compose.yml
的卷列表中。我花了一段时间才明白如何正确地让一切正常工作
【讨论】:
【参考方案4】:只需运行sequelize init
,它将在您的项目中创建 config 文件夹,并在此文件夹中创建 config.json。
之后根据需要更改 config.json 以进行连接
“发展”: “用户名”:“postgres”, “密码”:“123”, “数据库”:“用户”, “主机”:“本地主机”, “方言”:“postgres”, “运营商别名”:假
【讨论】:
以上是关于错误:找不到“/config/config.json”。你有没有运行“续集初始化”?的主要内容,如果未能解决你的问题,请参考以下文章
易语言的错误怎么办错误(36): 找不到指定的对象成员命令名称“创建内存”
易语言:错误(36): 找不到指定的对象成员命令名称“打开”。