按照http://docs.grafana.org/project/building_from_source/中的说明,我可以构建Grafana并启动服务器监听http://localhost:3000,但CSS显然无效。我试图重新执行构建前端资产的构建命令,但我遇到了错误,其顺序如下:
npm install
npm install -g grunt-cli
grunt
目前尚不清楚应该从哪个目录执行这些命令。我假设$ GOPATH / src / github.com / grafana / grafana但是当我执行第一个命令npm install
时,我得到一系列错误,如下所示:
npm WARN locking Error: EACCES, open '/Users/sam/.npm/_locks/glob-386d0e7784ce4d2e.lock'
npm WARN locking at Error (native)
npm WARN locking /Users/sam/.npm/_locks/glob-386d0e7784ce4d2e.lock failed { [Error: EACCES, open '/Users/sam/.npm/_locks/glob-386d0e7784ce4d2e.lock']
npm WARN locking errno: -13,
npm WARN locking code: 'EACCES',
npm WARN locking path: '/Users/sam/.npm/_locks/glob-386d0e7784ce4d2e.lock' }
npm ERR! Darwin 14.0.0
npm ERR! argv "node" "/usr/local/bin/npm" "install"
npm ERR! node v0.12.7
npm ERR! npm v2.11.3
npm ERR! Attempt to unlock /Users/sam/Projects/go/src/github.com/grafana/grafana/node_modules/glob, which hasn't been locked
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
我从这里https://nodejs.org/download/docs/latest/安装了NodeJS,我已经检查了/ usr / local / bin是否存在npm并且它存在,但我不确定在安装时是否错过了配置步骤。
当我转到执行npm install -g grunt-cli
的下一步时,我得到一个错误块(类似于前一个),如下所示:
npm WARN locking Error: EACCES, open '/Users/sam/.npm/_locks/grunt-cli-58f484dab06f0a30.lock'
npm WARN locking at Error (native)
npm WARN locking /Users/sam/.npm/_locks/grunt-cli-58f484dab06f0a30.lock failed { [Error: EACCES, open '/Users/sam/.npm/_locks/grunt-cli-58f484dab06f0a30.lock']
npm WARN locking errno: -13,
npm WARN locking code: 'EACCES',
npm WARN locking path: '/Users/sam/.npm/_locks/grunt-cli-58f484dab06f0a30.lock' }
npm ERR! Darwin 14.0.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "grunt-cli"
npm ERR! node v0.12.7
npm ERR! npm v2.11.3
npm ERR! Attempt to unlock /usr/local/lib/node_modules/grunt-cli, which hasn't been locked
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /Users/sam/Projects/go/src/github.com/grafana/grafana/npm-debug.log
最后,当我执行grunt
时,我收到以下致命错误:
grunt-cli: The grunt command line interface. (v0.1.13)
Fatal error: Unable to find local grunt.
If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:
http://gruntjs.com/getting-started
我还验证了项目目录中有package.json和Gruntfile.js文件。如果有帮助,以下是所有文件的列表:
09:25:54|~/Projects/go/src/github.com/grafana/grafana$ ls -alF
total 47648
drwxr-xr-x 42 sam staff 1428 Sep 5 21:21 ./
drwxr-xr-x 3 sam staff 102 Sep 5 17:59 ../
-rw-r--r-- 1 sam staff 36 Sep 5 18:02 .bowerrc
-rw-r--r-- 1 sam staff 344 Sep 5 18:02 .bra.toml
-rw-r--r-- 1 sam staff 197 Sep 5 18:02 .editorconfig
drwxr-xr-x 13 sam staff 442 Sep 5 19:28 .git/
-rw-r--r-- 1 sam staff 345 Sep 5 18:02 .gitignore
drwxr-xr-x 3 sam staff 102 Sep 5 18:02 .hooks/
-rw-r--r-- 1 sam staff 418 Sep 5 18:02 .jscs.json
-rw-r--r-- 1 sam staff 287 Sep 5 18:02 .jsfmtrc
-rw-r--r-- 1 sam staff 564 Sep 5 18:02 .jshintrc
-rw-r--r-- 1 sam staff 54566 Sep 5 18:02 CHANGELOG.md
-rw-r--r-- 1 sam staff 571 Sep 5 18:02 CONTRIBUTING.md
drwxr-xr-x 5 sam staff 170 Sep 5 18:02 Godeps/
-rw-r--r--@ 1 sam staff 1289 Sep 5 18:02 Gruntfile.js
-rw-r--r-- 1 sam staff 578 Sep 5 18:02 LICENSE.md
-rw-r--r-- 1 sam staff 638 Sep 5 18:02 NOTICE.md
-rw-r--r-- 1 sam staff 5286 Sep 5 18:02 README.md
-rw-r--r-- 1 sam staff 591 Sep 5 18:02 appveyor.yml
drwxr-xr-x 3 sam staff 102 Sep 5 18:02 benchmarks/
drwxr-xr-x 4 sam staff 136 Sep 5 19:28 bin/
-rw-r--r-- 1 sam staff 569 Sep 5 18:02 bower.json
-rw-r--r-- 1 sam staff 11721 Sep 5 18:02 build.go
-rw-r--r-- 1 sam staff 637 Sep 5 18:02 circle.yml
drwxr-xr-x 5 sam staff 170 Sep 5 18:02 conf/
drwxr-xr-x 5 sam staff 170 Sep 5 18:50 data/
drwxr-xr-x 8 sam staff 272 Sep 5 18:02 docker/
drwxr-xr-x 9 sam staff 306 Sep 5 18:02 docs/
drwxr-xr-x 8 sam staff 272 Sep 5 18:02 emails/
-rw-r--r--@ 1 sam staff 35472 Sep 5 19:46 err.txt
-rwxr-xr-x 1 sam staff 24195460 Sep 5 18:49 grafana*
-rw-r--r-- 1 sam staff 24 Sep 5 18:02 latest.json
-rw-r--r-- 1 sam staff 2857 Sep 5 18:02 main.go
-rw-r--r-- 1 sam staff 6693 Sep 5 21:21 npm-debug.log
-rw-r--r--@ 1 sam staff 1870 Sep 5 18:02 package.json
drwxr-xr-x 4 sam staff 136 Sep 5 18:02 packaging/
drwxr-xr-x 17 sam staff 578 Sep 5 18:02 pkg/
drwxr-xr-x 12 sam staff 408 Sep 5 18:02 public/
drwxr-xr-x 7 sam staff 238 Sep 5 18:02 tasks/
-rwxr-xr-x 1 sam staff 1178 Sep 5 18:02 test.sh*
drwxr-xr-x 3 sam staff 102 Sep 5 18:02 tests/
drwxr-xr-x 3 sam staff 102 Sep 5 18:02 vendor/
当我使用./bin/grafana-server
(来自$ GOPATH / src / github.com / grafana / grafana)启动服务器时,我得到预期的输出,但随后导航到http://localhost:3000,最后一行带有404错误添加如下:
09:27:13|~/Projects/go/src/github.com/grafana/grafana$ ./bin/grafana-server
2015/09/05 21:34:22 [I] Starting Grafana
2015/09/05 21:34:22 [I] Version: 2.2.0-pre1, Commit: v2.1.2+199-gf27f028, Build date: 2015-09-04 08:34:01 -0700 MST
2015/09/05 21:34:22 [I] Configuration Info
Config files:
[0]: /Users/sam/Projects/go/src/github.com/grafana/grafana/conf/defaults.ini
Paths:
home: /Users/sam/Projects/go/src/github.com/grafana/grafana
data: /Users/sam/Projects/go/src/github.com/grafana/grafana/data
logs: /Users/sam/Projects/go/src/github.com/grafana/grafana/data/log
2015/09/05 21:34:22 [I] Database: sqlite3
2015/09/05 21:34:22 [I] Migrator: Starting DB migration
2015/09/05 21:34:22 [I] Listen: http://0.0.0.0:3000
2015/09/05 21:36:33 [I] Completed /css/grafana.dark.min.css 404 Not Found in 1.799267ms
以下是项目中包含的Gruntfile.js的内容(即我没写过):
/* jshint node:true */
'use strict';
module.exports = function (grunt) {
var os = require('os');
var config = {
pkg: grunt.file.readJSON('package.json'),
baseDir: '.',
srcDir: 'public',
destDir: 'dist',
tempDir: 'tmp',
arch: os.arch(),
platform: process.platform.replace('win32', 'windows'),
};
if (process.platform.match(/^win/)) {
config.arch = process.env.hasOwnProperty('ProgramFiles(x86)') ? 'x64' : 'x86';
}
config.pkg.version = grunt.option('pkgVer') || config.pkg.version;
// load plugins
require('load-grunt-tasks')(grunt);
// load task definitions
grunt.loadTasks('tasks');
// Utility function to load plugin settings into config
function loadConfig(config,path) {
require('glob').sync('*', {cwd: path}).forEach(function(option) {
var key = option.replace(/\.js$/,'');
// If key already exists, extend it. It is your responsibility to avoid naming collisions
config[key] = config[key] || {};
grunt.util._.extend(config[key], require(path + option)(config,grunt));
});
// technically not required
return config;
}
// Merge that object with what with whatever we have here
loadConfig(config,'./tasks/options/');
// pass the config to grunt
grunt.initConfig(config);
};
此外,由于它被要求,这里是项目中所有CSS文件的列表(虽然我不确定这些是否是UI使用的CSS文件):
10:23:03|~/Projects/go/src/github.com/grafana/grafana$ find . -iname "*.css"
./emails/assets/css/ink.css
./emails/assets/css/style.css
./public/vendor/angular/angular-csp.css
./public/vendor/angular-native-dragdrop/demo/css/styles.css
./public/vendor/angular-native-dragdrop/docs/css/styles.css
./public/vendor/css/font-awesome.min.css
./public/vendor/css/normalize.min.css
./public/vendor/css/spectrum.css
./public/vendor/css/timepicker.css
有没有人对如何使CSS正常工作有任何建议?我希望我错过了一些明显的东西但是我已经在这里呆了几个小时了,找不到任何有用的东西。谢谢!
答案 0 :(得分:0)
导入css时可能缺少路径。
可能只是在路径中添加'public / vendor'就可以解决这个问题。
关于grunt文件,看起来节点正在将任务加载到另一个文件夹中:
loadConfig(config,'./tasks/options/');
so I think you should update the question or look up the tasks at this line
你可以看到grunt url
的文件示例查看grunt对默认任务的处理方式(例如:$ grunt)