Coder Social home page Coder Social logo

Comments (15)

shama avatar shama commented on August 19, 2024

Could you post the gruntfile that generated this error?

from grunt-contrib-connect.

makotot avatar makotot commented on August 19, 2024

i'm also having same problem and my Gruntfile is below.

File: [no files]
Warning: Object /Users/hoge/dev/project has no method 'charAt' Use --force to continue.
TypeError: Object /Users/hoge/dev/project has no method 'charAt'
    at exports.normalize (path.js:336:27)
    at Function.directory (/Users/hoge/dev/project/node_modules/grunt-contrib-connect/node_modules/connect/lib/middleware/directory.js:56:14)
    at Object.grunt.initConfig.connect.livereload.options.middleware (/Users/hoge/dev/project/Gruntfile.js:35:16)
    at Object.<anonymous> (/Users/hoge/dev/project/node_modules/grunt-contrib-connect/tasks/connect.js:64:62)
    at Object.<anonymous> (/Users/hoge/dev/project/node_modules/grunt/lib/grunt/task.js:258:15)
    at Object.thisTask.fn (/Users/hoge/dev/project/node_modules/grunt/lib/grunt/task.js:78:16)
    at Object.<anonymous> (/Users/hoge/dev/project/node_modules/grunt/lib/util/task.js:282:30)
    at Task.runTaskFn (/Users/hoge/dev/project/node_modules/grunt/lib/util/task.js:235:24)
    at Task.<anonymous> (/Users/hoge/dev/project/node_modules/grunt/lib/util/task.js:281:12)
    at Task.<anonymous> (/Users/hoge/dev/project/node_modules/grunt/lib/util/task.js:215:7)
module.exports = function (grunt) {
    'use strict';

    grunt.initConfig({
        watch: {
            html: {
                files: '**/*.html',
                tasks: [],
                options: {
                    livereload: true,
                    nospawn: true
                }
            },
            js: {
                files: 'public/js/*.js',
                tasks: ['jshint'],
                options: {
                    livereload: true,
                    nospawn: true
                }
            }
        },

        connect: {
            livereload: {
                options: {
                    port: 9001,
                    hostname: '0.0.0.0',
                    base: './',
                    middleware: function (connect, options) {
                        return [
                            require('connect-livereload')(),
                            connect.static(options.base),
                            connect.directory(options.base)
                        ];
                    }
                }
            }
        },

        jshint: {
            files: {
                src: ['public/js/*.js']
            }
        }

    });

    grunt.event.on('watch', function (action, filepath) {
        grunt.log.write(action, filepath);
    });

    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-connect');

    grunt.registerTask('default', ['connect', 'watch']);
};

from grunt-contrib-connect.

abahdanovich avatar abahdanovich commented on August 19, 2024

Here is excerpt from my Gruntfile.coffee

connect:
      options:
        hostname: "<%= connect_hostname %>"
        middleware: (connect, options) ->
          modRewrite = require("connect-modrewrite")
          [modRewrite(["^/#/.*$ /index.html [L]"]), connect.static(options.base)]

      dev:
        options:
          port: 9001
          base: "public"

If you need any other details please let me know.

from grunt-contrib-connect.

shama avatar shama commented on August 19, 2024

Ah I think it's because options.base is now an array as it accepts multiple base paths. Since the more common use case is a single path, maybe it would make more sense to check if the array only has one path and bring it back to a string so the above examples will continue to work. Thoughts?

/cc @sindresorhus @cowboy

from grunt-contrib-connect.

abahdanovich avatar abahdanovich commented on August 19, 2024

Ah I think it's because options.base is now an array as it accepts multiple base paths.

Yes, this is the reason (checked with debugger)...
normalize() expects path as a string, but is given an array

from grunt-contrib-connect.

cowboy avatar cowboy commented on August 19, 2024

The options.base property is now normalized to an array internally. Unfortunately, we forgot that people might be using that property inside their own custom middleware, and thus caused this regression.

A short-term solution would be for you to use options.base[0] or String(options.base) inside your Gruntfile.

We need to figure out if we need to revert this change or to maintain the same behavior, but do so it in a way that leaves the original options.base property untouched.

from grunt-contrib-connect.

shama avatar shama commented on August 19, 2024

Ok treating this as a bug then and will un-normalize options.base. So if the user provides a string, it will be a string otherwise if multiple bases, it will be an array.

from grunt-contrib-connect.

abahdanovich avatar abahdanovich commented on August 19, 2024

Patch you provided fixes the problem - thank you for your help!

from grunt-contrib-connect.

gcoonrod avatar gcoonrod commented on August 19, 2024

I am seeing this issue again in the latest version.

TypeError: Object /Users/gcoonrod/dev/galileo-training has no method 'charAt'
    at exports.normalize (path.js:336:27)
    at SendStream.root.SendStream.from (/Users/gcoonrod/dev/galileo-training/node_modules/grunt-contrib-connect/node_modules/connect/node_modules/send/lib/send.js:116:16)
    at Object.staticMiddleware [as handle] (/Users/gcoonrod/dev/galileo-training/node_modules/grunt-contrib-connect/node_modules/connect/lib/middleware/static.js:86:8)
    at next (/Users/gcoonrod/dev/galileo-training/node_modules/grunt-contrib-connect/node_modules/connect/lib/proto.js:193:15)
    at Object.livereload [as handle] (/Users/gcoonrod/dev/galileo-training/node_modules/connect-livereload/index.js:147:5)
    at next (/Users/gcoonrod/dev/galileo-training/node_modules/grunt-contrib-connect/node_modules/connect/lib/proto.js:193:15)
    at Function.app.handle (/Users/gcoonrod/dev/galileo-training/node_modules/grunt-contrib-connect/node_modules/connect/lib/proto.js:201:3)
    at Server.app (/Users/gcoonrod/dev/galileo-training/node_modules/grunt-contrib-connect/node_modules/connect/lib/connect.js:65:37)
    at Server.EventEmitter.emit (events.js:98:17)
    at HTTPParser.parser.onIncoming (http.js:2108:12)

Any further updates on how to address?

Here are the grunt modules i'm using

"devDependencies": {
    "grunt": "~0.4.2",
    "grunt-contrib-concat": "~0.3.0",
    "connect-livereload": "~0.3.2",
    "grunt-contrib-watch": "~0.5.3",
    "grunt-contrib-connect": "~0.7.1",
    "grunt-htmlhint": "~0.4.0",
    "grunt-contrib-jshint": "~0.8.0",
    "grunt-contrib-csslint": "~0.2.0"
  }

And the Gruntfile.js

module.exports = function(grunt){
    var LIVERELOAD_PORT = 35728;
    var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});
    var livereloadMiddleware = function (connect, options){
        return [
            lrSnippet,
            connect.static(options.base),
            connect.directory(options.base)
        ];
    };

    grunt.initConfig({
        connect: {
            client: {
                options: {
                    port: 9001,
                    hostname: 'localhost',
                    base: new '.',      //For Windows
                    //base: '/Users/gcoonrod/dev/galileo-training/', //For Mac
                    middleware: livereloadMiddleware 
                }
            }
        },

        watch: {
            client: {
                files: [
                    'views/**/*',
                    'css/**/*',
                    'scripts/**/*',
                    'test/**/*', 
                    'index.html'
                ],
                tasks: ['htmlhint'],
                options: {
                    livereload:LIVERELOAD_PORT
                }
            }
        },

        htmlhint: {
            build: {
                options: {
                    'tag-pair': true,
                    'tagname-lowercase': true,
                    'attr-lowercase': true,
                    'attr-value-double-quotes': true,
                    'id-unique': true,
                    'style-disabled': true
                },
                src: [
                    'views/**/*.html', 
                    'index.html'
                ]
            }
        },

        jshint: {
            options: {
                eqeqeq: true,
                browser: true,
                globals: {
                    jQuery: true,
                    devel: true,
                    worker: true,
                    angular: true
                }
            },
            ignore_warning: {
                options: {
                    '-W099': true,
                    '-W030': true
                },
                src: [
                    ''
                ]
            },
            files: {
                src: [
                    'Gruntfile.js',
                    'scripts/**/*.js',
                    'test/**/*.js'
                ]
            }
        }
    });



    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-htmlhint');
    grunt.loadNpmTasks('grunt-contrib-jshint');

    grunt.registerTask('server', ['build', 'connect:client', 'watch:client']);
    grunt.registerTask('build', ['htmlhint']);
}

from grunt-contrib-connect.

shama avatar shama commented on August 19, 2024

@gcoonrod I think this part base: new '.' should just be base: '.'. The new keyword is for instantiating an object (and I'm surprised it's not throwing a type error for you).

from grunt-contrib-connect.

gcoonrod avatar gcoonrod commented on August 19, 2024

Sorry, that was a left over from trying new Array('.') I've removed it already and still get the same error.

from grunt-contrib-connect.

abahdanovich avatar abahdanovich commented on August 19, 2024

I had exactly the same situation a week or two ago...

    connect:
      options:
        hostname: CONNECT_HOSTNAME
        middleware: (connect, options) ->
          modRewrite = require("connect-modrewrite")
          [connect.logger('dev'), modRewrite(["^/#/.*$ /index.html [L]"]), connect.static(options.base)]

Changing options.base to String(options.base) seems to solve the problem, but I'm not sure whether it is the right solution of the problem...

from grunt-contrib-connect.

gcoonrod avatar gcoonrod commented on August 19, 2024

String(options.base) in the middleware config worked. Thank you.

from grunt-contrib-connect.

cowboy avatar cowboy commented on August 19, 2024

connect.static expects a string, but if your options.base is an array, you're going to have problems. The default middleware actually iterates over the options.base array and calls connect.static once for each item.

from grunt-contrib-connect.

yankee42 avatar yankee42 commented on August 19, 2024

I believe that the documentation still needs some fixing. The without livereload still suffers from the problem.

from grunt-contrib-connect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.