Comments (15)
Could you post the gruntfile that generated this error?
from grunt-contrib-connect.
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.
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.
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.
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.
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.
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.
Patch you provided fixes the problem - thank you for your help!
from grunt-contrib-connect.
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.
@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.
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.
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.
String(options.base)
in the middleware config worked. Thank you.
from grunt-contrib-connect.
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.
I believe that the documentation still needs some fixing. The without livereload still suffers from the problem.
from grunt-contrib-connect.
Related Issues (20)
- Can this connect from a remote server to either the web or to my local machine?
- ExperimentalWarning: The http2 module is an experimental API. HOT 6
- forwarding grunt connect to different url HOT 2
- DES3 is a weak cipher
- warning corifeus-builder-angular > grunt-contrib-connect > [email protected]: Use the built-in module in node 9.0.0 or newer, instead HOT 10
- Can I force TLS 1.2? HOT 2
- Can we use this with helmet? HOT 1
- Changing content type of files HOT 2
- Is it possible to configure the mime type returned by grunt-contrib-connect? HOT 1
- Options are just being ignored HOT 1
- This project's build is currently broken. HOT 1
- How to preview a Markdown file?
- Port parameter passed in as string leads to misleading error HOT 1
- Upgrade morgan package, CVE-2019-5413
- Cannot access Angular App hosted on CentOS 7 VM in Windows 10
- Security vulnerability GHSA-6fc8-4gx4-v693 affecting "ws" package (nested dependency) HOT 2
- opn dependency was renamed to `open` HOT 1
- `node-http2` is deprecated. Use node's built in `http2` HOT 6
- Fix vulnerability from websocket dependency: Denial of Service HOT 2
- IPv4 loopback overridden
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grunt-contrib-connect.