Modernizr: Can't require('modernizr')

I am using webpack to modularize and bundle my code (it’s like browserify but with some advantages). I installed Modernizr 3.0.0-alpha4 via npm and required Modernizr in my code. Unfortunately I get following error:

1 vagrant@vagrant-ubuntu-trusty-64 /vagrant % webpack                                                      :(
Hash: d313d14e909b8cd939c0
Version: webpack 1.9.7
Time: 894ms
    Asset    Size  Chunks             Chunk Names
bundle.js  717 kB       0  [emitted]  main
    + 173 hidden modules

ERROR in ./~/modernizr/package.json
Module parse failed: /vagrant/node_modules/modernizr/package.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
|   "name": "modernizr",
|   "version": "3.0.0-alpha.4",
|   "description": "Modernizr is a JavaScript library that detects HTML5 and CSS3 features in the user’s browser.",
 @ ./~/modernizr/lib/build.js 131:12-38

ERROR in ./~/modernizr/lib/build.js
Module not found: Error: Cannot resolve module 'generate' in /vagrant/node_modules/modernizr/lib
 @ ./~/modernizr/lib/build.js 147:2-72

ERROR in ./~/modernizr/lib/build.js
Module not found: Error: Cannot resolve module 'lib/generate-banner' in /vagrant/node_modules/modernizr/lib
 @ ./~/modernizr/lib/build.js 147:2-72

ERROR in ./~/modernizr/lib/build.js
Module not found: Error: Cannot resolve module 'package' in /vagrant/node_modules/modernizr/lib
 @ ./~/modernizr/lib/build.js 147:2-72

ERROR in ./~/modernizr/lib/metadata.js
Module not found: Error: Cannot resolve module 'fs' in /vagrant/node_modules/modernizr/lib
 @ ./~/modernizr/lib/metadata.js 1:9-22

ERROR in ./~/modernizr/lib/polyfills.json
Module parse failed: /vagrant/node_modules/modernizr/lib/polyfills.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
|   "html5shiv": {
|     "name": "HTML5 Shiv",
|     "authors": ["Alexander Farkas (@aFarkas)", "Jonathan Neal (@jonathantneal)", "Paul Irish (@paulirish)"],
 @ ./~/modernizr/lib/metadata.js 4:16-43

ERROR in ./~/modernizr/~/requirejs/bin/r.js
Module parse failed: /vagrant/node_modules/modernizr/node_modules/requirejs/bin/r.js Line 1: Unexpected token ILLEGAL
You may need an appropriate loader to handle this file type.
| #!/usr/bin/env node
| /**
|  * @license r.js 2.1.17 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved.
 @ ./~/modernizr/lib/build.js 129:18-38

ERROR in ./~/modernizr/~/file/lib/file.js
Module not found: Error: Cannot resolve module 'fs' in /vagrant/node_modules/modernizr/node_modules/file/lib
 @ ./~/modernizr/~/file/lib/file.js 2:9-22

I saw the issues #1527, #1431 and #1204 but I don’t get the solution. Will this possible in the final 3.0 release or is this still supported in the current alpha version?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

totally, but it would be a built file, not the npm lib.

This seems unfortunate. There are many advantages to being able to pull directly from npm.

  1. You don’t need to have a separate package manager (like bower) or commit the built file to your repo.
  2. Many projects allow you to pull in only what you need. For instance, lodash/object/assign or react vs react/addons. You could (possibly) mimic the “configure your build” functionality purely through require statements. If some component no longer needs to check for canvas support, it can remove the appropriate require statement and assuming no other components require modernizr/canvas then the canvas functionality would just be dropped from the build automatically.

hey @akoskm !

… which doesn’t require any re-architecting.

We actually want to do the rearch. With ES6 modules coming in the near future, we want to build the modular subsystem based on where the browsers are going, rather than where they have been. I already have written 95% of the rewrite, the biggest issue facing me at the moment is getting tests back in working order (they were previously written with requirejs)

How about wrapping… with [UMD]

Thats actually what the rewrite is doing already

…would https://github.com/Modernizr/builder-ui be a more appropriate …

The building system is the universal builder, which is in this repo. Also, builder-ui is the old site, the new one being modernizr-neue. So thanks a ton! But no need, we are on it already :].