jquery-validation-unobtrusive: Webpack build with version 3.2.8 is failing

When using the latest version from NPM (3.2.8) with webpack, the following error occurres:

ERROR in ./node_modules/jquery-validation-unobtrusive/dist/jquery.validate.unobtrusive.js
Module not found: Error: Can't resolve 'jquery.validate' in '[path]\node_modules\jquery-validation-unobtrusive\dist'
 @ ./node_modules/jquery-validation-unobtrusive/dist/jquery.validate.unobtrusive.js 11:8-75
 @ multi bootstrap jquery jquery-validation jquery-validation-unobtrusive popper.js

I think webpack tries to resolve jquery.validate as a dependency (via AMD define) but it fails because it’s probably known within webpack as jquery-validation. A workaround is to add the following rule to the webpack config:

module: {
  rules: [
    {
      parser: {
        amd: false,
      }
    }, 
   ...other rules...
  ]
}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 19 (7 by maintainers)

Commits related to this issue

Most upvoted comments

For people using webpack, the easiest option is to alias jquery.validate in the resolve block of webpack. Below tested with Webpack 4 (latest) and latest versions of both jquery-validation and jquery-validation-unobtrusive. This way there is no need to hack the jquery-validation-unobtrusive package files, and when the offending lines are fixed in a next release your webpack build will keep working.

alias: {
  "jquery.validation': "jquery-validation/dist/jquery.validate.js" 
},

Since CI/CD is not implemented, when will this fix be pushed to npm?

@kichalla This is not fixed. You changed it from jquery.validate to jquery.validation. It needs to be jquery-validation.

Just FYI, a new version (3.2.10) having the correct fix for this has been published to npm registry few minutes ago.

Same here, downgrading to 3.2.6 works again. For those unfamiliar with semver: remove the ^ from package.json before 3.2.6 or it will force an update to 3.2.8 since it’s a patchversion.

EDIT: Only read half the issue, as is tradition on the interwebs. Disabling AMD also works if you want to update.

The problem is that jquery unobtrusive is trying to load module with name jquery.validate. But such module is not valid because in latest version of jquery-validation export was defined as jquery Check it here. https://cdn.jsdelivr.net/npm/jquery-validation@1.17.0/dist/jquery.validate.js

(function( factory ) {
	if ( typeof define === "function" && define.amd ) {
		define( ["jquery"], factory );
	} else if (typeof module === "object" && module.exports) {
		module.exports = factory( require( "jquery" ) );
	} else {
		factory( jQuery );
	}
}(function( $ ) {
// jquery validation code 
})

I think this is bug in jquery-validation itself because docs says that you need to require dependency jquery.validate but not jquery.

So the quick fix would just replacing jquery.validate to jquery in jquery-validation-unobtrusive library or jquery to jquery.validate in jquery-validation library.