gruntjs / grunt-contrib-connect

Start a static web server.
http://gruntjs.com
MIT License
714 stars 146 forks source link

Version 0.9.0 doesn't work with minimal example #161

Closed hugocorbucci closed 9 years ago

hugocorbucci commented 9 years ago

Tried creating a simple grunt-contrib-connect example and having errors. Check this sample project: https://github.com/hugocorbucci/grunt-connect-example

Works for 0.8.0 but breaks for 0.9.0 with the following error:

$ grunt
Running "connect:server" (connect) task
Warning: Object function createServer() {
  function app(req, res, next){ app.handle(req, res, next); }
  merge(app, proto);
  merge(app, EventEmitter.prototype);
  app.route = '/';
  app.stack = [];
  return app;
} has no method 'static' Use --force to continue.

Aborted due to warnings.
johannesspohr commented 9 years ago

+1

ghost commented 9 years ago

+1

johannesspohr commented 9 years ago

The problem seems to be that it's not compatible with connect 3 (static is now serve-static), The dependency is correct in the package.json, but since express was already in my project in version 3, npm did not install it for grunt-contrib-connect i guess.

hayesmaker commented 9 years ago

+1

conanmy commented 9 years ago

+1 anyone solved this?

vladikoff commented 9 years ago

fixed in 0.11.0

samsong8610 commented 9 years ago

@vladikoff v0.11.2 still has this issue.

$ npm list grunt-contrib-connect
yeoman@ /home/sam/sandbox/js/yeoman
└── grunt-contrib-connect@0.11.2 

$ grunt serve Running "serve" task

Running "clean:server" (clean) task

1 path cleaned.

Running "wiredep:app" (wiredep) task

Running "wiredep:test" (wiredep) task

Running "concurrent:server" (concurrent) task

Running "copy:styles" (copy) task
Copied 1 file

Done, without errors.

Execution Time (2015-09-15 01:11:50 UTC)
loading tasks               219ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 89%
loading grunt-contrib-copy   15ms  ▇▇▇ 6%
copy:styles                  11ms  ▇▇ 4%
Total 246ms

Running "autoprefixer:server" (autoprefixer) task Autoprefixer's process() method is deprecated and will removed in next major release. Use postcss([autoprefixer]).process() instead File .tmp/styles/main.css created.

Running "connect:livereload" (connect) task Warning: Object function createServer() { function app(req, res, next){ app.handle(req, res, next); } merge(app, proto); merge(app, EventEmitter.prototype); app.route = '/'; app.stack = []; return app; } has no method 'static' Use --force to continue.

Aborted due to warnings.

Execution Time (2015-09-15 01:11:49 UTC) loading tasks 185ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 15% wiredep:app 179ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 14% wiredep:test 13ms ▇▇ 1% concurrent:server 551ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 45% loading grunt-autoprefixer 228ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 18% autoprefixer:server 52ms ▇▇▇▇▇ 4% Total 1.2s

hilteci commented 9 years ago

I have this exact problem as well, and I've now tested it on all the 0.11.x versions. The serve-static issue seems to be resolved as of 0.11.13 (and stays that way all the way through 0.12.x), but then I get:

Running "connect:development" (connect) task
Warning: undefined is not a function Use --force to continue.

I can't figure out what's causing this either. Anyone solved a undefined is not a function issue like this using grunt connect and node 0.11.13 or higher?

samsong8610 commented 9 years ago

The project generated from yo 1.4.8 use grunt-contrib-connect@0.9.0, import dependency to connect@2.30.2. This version connect support connect().static() method. In the Gruntfile.js, yo configure a middleware for connect:livereload, in which static() method was used. But after installed grunt-contrib-connect@0.12.2, which depends on connect@3, the middleware code generated by yo is broken. I think this issue should be resolved by yeoman guys.

acedesigns commented 8 years ago

Hi Guys.

I was having the same problem, and I found a solution by doing the following. Even though I kow its not the right way of doing it. I was pressed for time. So I down graded grunt-contrib-connect from 0.11.0 to 0.8.0. Which is a big jump.

Package.json

{
 "name" : "myApp",
 "dependencies" : {
   "grunt": "0.4.5",
   "grunt-contrib-connect" : "0.8.0",
   "grunt-contrib-watch"      : "0.6.0",
   "grunt-wiredep"        : "1.9.0"    
 }
}

Gruntfile.js

module.exports = function(grunt) {
  grunt.initConfig({
   //My Tasks
  });

grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
    grunt.task.run([
      'wiredep',
      'connect:livereload',
      'watch'
    ]);
  });
};

Now I can run my grunt serve with no problems