gpt4 book ai didi

docker - 在 docker : Fatal error: Unable to find local grunt 中运行 grunt 时出错

转载 作者:行者123 更新时间:2023-12-01 12:26:21 25 4
gpt4 key购买 nike

我正在尝试使用 docker 中的所有依赖项运行我的项目,但我遇到了 grunt 依赖项,由于某种原因 grunt 失败,并显示无法找到本地 grunt 的错误。

我创建了一个如何重现此示例的示例:

.
├── code
│   ├── bower.json
│   ├── Gruntfile.js
│   └── package.json
├── docker-compose.yml
└── frontend.dockerfile

docker-compose.yml :
version: "2"
services:
frontend:
build:
context: .
dockerfile: frontend.dockerfile
ports:
- "8585:8000"
volumes:
- ./code:/srv/frontend
command: grunt

前端.dockerfile :
FROM node:wheezy

ADD code /srv/frontend
WORKDIR /srv/frontend
RUN npm install -g grunt-cli bower
RUN npm install

RUN groupadd -r usergroup && useradd -m -r -g usergroup user
RUN chown -R user:usergroup /srv/frontend
USER user

RUN bower install

bower.json :
{
"name": "code",
"description": "",
"main": "index.js",
"authors": [
"Mr. No One"
],
"license": "ISC",
"homepage": "",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"angular": "^1.5.8"
}
}

Gruntfile.json :
module.exports = function(grunt) {
grunt.initConfig({});

// tasks
grunt.registerTask('default', []);
};

package.json :
{
"name": "code",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"grunt": "^1.0.1"
}
}
$ docker-compose up
... installing all dependencies ...
安装后,尝试运行 grunt 失败我在 docker-compose.yml 中指定的命令出现此错误的文件:
frontend_1  | grunt-cli: The grunt command line interface (v1.2.0)
frontend_1 |
frontend_1 | Fatal error: Unable to find local grunt.
frontend_1 |
frontend_1 | If you're seeing this message, grunt hasn't been installed locally to
frontend_1 | your project. For more information about installing and configuring grunt,
frontend_1 | please see the Getting Started guide:
frontend_1 |
frontend_1 | http://gruntjs.com/getting-started
package.json实际上确实包括 grunt作为依赖项,它应该在 RUN npm install 之后安装.

最佳答案

做一个 docker exec -it <nameofyourcontainer> bash并查看 node_modules如果 grunt 安装在本地。

你设置了吗NODE_ENVproduction某处?
这会导致 npm不安装 devDepedencies .

关于docker - 在 docker : Fatal error: Unable to find local grunt 中运行 grunt 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39165918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com