【问题标题】:Grunt server not working in nitrous.ioGrunt 服务器在 nitrous.io 中不起作用
【发布时间】:2013-09-11 07:45:49
【问题描述】:

我使用nitrous.io 创建了一个节点环境。我在他们的终端里面安装了yeoman。 如果我尝试运行grunt server,我会收到一条错误消息:

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

如果我去预览而不是连接到端口 3000 我会得到这个

节点的引用状态将 127.0.0.1 或“localhost”更改为 0.0.0.0

  var http = require('http');
  http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
  }).listen(3000, '0.0.0.0');
  console.log('Server running at http://0.0.0.0:3000/');

Grunt 语法对于服务器来说有点不同

connect: {
      options: {
        port: 3000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: '0.0.0.0' // 
      },

即使在此更改之后,错误仍然存​​在。当我运行 grunt server 或去预览端口 3000 时失败

关于我做错了什么有什么想法吗?如何运行我的 grunt 服务器以便在浏览器中看到我的网站?

【问题讨论】:

    标签: node.js angularjs gruntjs yeoman nitrousio


    【解决方案1】:

    对于收到的第一条错误消息,您是否仔细阅读过建议?您需要 Gruntfile.jspackage.json (将 Grunt 列为依赖项); this is covered in the official documentation。然后,通过运行npm install,您将能够将本地 Grunt 拉入您的项目。

    【讨论】:

    • 这绝对是我第一次使用这种技术。来自 Rails 的简短背景。我只是忘了进行 npm 安装或捆绑安装。谢谢。
    • 我将其标记为正确,但您知道为什么我必须 grunt server --force 才能使服务器正常工作吗?它引发了关于指南针的错误,现在引导默认样式不起作用,我担心这是因为力
    • 如果你通过 Grunt 使用 sass 或 compass,你必须确保 gems 安装在你的系统上。这是抛出的错误吗? npm 不处理这些包,只处理与 Grunt 兼容的包装器,因此如果您没有安装这些包,请先执行此操作。 :)
    • 是 package.json = gemfile? gemfile也不应该看到我正在使用yeoman吗?非常感谢您的帮助
    • 不,这两个任务只需要你全局安装gem;即gem update --system; gem install sass; gem install compass
    【解决方案2】:

    总结一下这对我有用的 cmets:

    gem install sass; gem install compass
    yo webapp
    

    在第 43 行附近编辑 Gruntfile.js

    connect: {
      options: {
        port: 3000, // <- changed this line
        livereload: 35729,
        hostname: '0.0.0.0' // <- changed this line
    

    运行grunt server 并点击Preview-按钮/Port 3000

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-20
      • 2011-06-10
      • 2014-07-06
      相关资源
      最近更新 更多