Error while using custom tests
Closed this issue · 20 comments
When building with a custom test included with latest grunt-modernizr:
Fatal error: Cannot read property 'replace' of undefined
could you run grunt with the --debug
option to get the full stack trace?
$ grunt --debug modernizr
Running "modernizr:dist" (modernizr) task
[D] Task source: /home/build/src/test/node_modules/grunt-modernizr/tasks/modernizr.js
Skipping file traversal
>> Ready to build using these settings:
>> addTest, testStyles, setClasses
Building your customized ModernizrFatal error: Cannot read property 'replace' of undefined
--debug doesn't seem to add the line or file.
we are actually not using replace
anywhere in the task anymore. What version are you running? Can you share your grunt config?
grunt-cli v0.1.13
grunt v0.4.5
grunt-modernizr@1.0.1
could you share your grunt config
Yes,
and this test is used as custom test:
https://github.com/Modernizr/Modernizr/blob/master/feature-detects/css/hairline.js
perhaps I am not being clear.
Can your share the Gruntfile.js that you are using for development?
OK, I prepared a pared down example with the Gruntfile.js and the custom test that causes this error:
https://github.com/strarsis/customtest/tree/master
You can also find this Gruntfile.js in the link above:
module.exports = function(grunt) {
grunt.initConfig({
modernizr: {
dist: {
// Path to save out the built file.
'dest' : 'build/modernizr-custom.js',
// By default, source is uglified before saving
'uglify' : false,
// By default, this task will crawl your project for references to Modernizr tests
// Set to false to disable
'crawl' : false,
// Based on default settings on http://modernizr.com/download/
'options' : [
'addTest',
'testStyles',
'setClasses'
],
// Define any tests you want to implicitly include.
'tests' : [],
// Have custom Modernizr tests? Add paths to their location here.
'customTests' : [
'./custom-tests/hairline.js'
]
}
}
});
grunt.loadNpmTasks('grunt-modernizr');
grunt.registerTask('default',['modernizr:dist']);
}
So I further debugged this and found out the following:
The underlying modernizr module used by grunt-modernizr
tries to resolve the path to the custom test file as amd path,
which is not the case for custom tests, at least not documented:
https://github.com/Modernizr/Modernizr/blob/v3.2.0/lib/build-query.js#L5
The function will return undefined, the function generateBuildQuery will further process it
and tries to use replace prototype on it which will fail (as it is undefined).
out of curiosity, why are you using a test that is included as a custom test? Custom tests are for things that are not included in modernizr
The PR for the hairline test has been merged to master, however, I still use stable modernizr release.
What exactly is the purpose of customTests options - have I misunderstood its usage?
Oh, I apologize. Didn't realize we hadn't done a release since then. Technically you are doing the correct thing.
The idea for customTests
is things that you wish to use the Modernizr convenience APIs for. If we decided to not merge the hariline test, you could have included it yourself like you did.
So this is still to be considered as a bug?
Apparently customizr which is used by grunt-modernizr is also affected by this issue:
[...]
tests = [...]
}).concat(settings.customTests.map(function (test) {
return path.relative(buildPath, fs.realpathSync(test));
}));
[...]
[...]
var modernizrOptions = {
"feature-detects": tests,
[...]
The custom tests (paths to their files) are passed as feature-detects to Modernizr build
which cause the issue with Modernizr trying to resolve them amd style.
So is this a bug with grunt-modernizr, customizr or Modernizr?
yep, this is a bug.
On Wed, Dec 2, 2015 at 3:39 PM, strarsis notifications@github.com wrote:
So this is still to be considered as a bug?
Apparently customizr which is used by grunt-modernizr is also affected by
this issue:[...]
tests = [...]
}).concat(settings.customTests.map(function (test) {
return path.relative(buildPath, fs.realpathSync(test));
}));
[...][...]
var modernizrOptions = {
"feature-detects": tests,
[...]The custom tests (paths to their files) are passed as feature-detects to
Modernizr build
which cause the issue with Modernizr trying to resolve them amd style.With best regards
—
Reply to this email directly or view it on GitHub
#138 (comment)
.
patrick
File/concept of
https://github.com/Modernizr/Modernizr/blob/v3.0.0/lib/build-query.js#L5
has been introduced in Modernizr v3.x, I hadn't encountered this issue with v2.x.
Either the API has changed in an incompatible way to grunt-modernizr or customizr,
or this seems to be a bug with Modernizr instead.
yep - thank you very much for doing the digging
it'll be fixed shortly.
thanks for the report!
On Wed, Dec 2, 2015 at 3:43 PM, strarsis notifications@github.com wrote:
File/concept of
https://github.com/Modernizr/Modernizr/blob/v3.0.0/lib/build-query.js#L5
has been introduced in Modernizr v3.x, I hadn't encountered this issue
with v2.x.Either the API has changed in an incompatible way to grunt-modernizr or
customizr,
or this semes to be a bug with Modernizr instead.—
Reply to this email directly or view it on GitHub
#138 (comment)
.
patrick
Hi
I've just encountered this bug too
Any updates ?
No, apparently not.
This is the underlying issue: Modernizr/customizr#22
there isn't anything to do in grunt-modernizr with this issue (its a Modernizr issue at its core). You can follow along with the fix as Modernizr/Modernizr/#1799