1

按照此处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 正常工作有任何建议吗?我希望我遗漏了一些明显的东西,但我已经在这工作了几个小时,找不到任何有帮助的东西。谢谢!

4

1 回答 1

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)

于 2015-09-06T05:39:40.290 回答