简体   繁体   中英

ERROR in jQuery is not defined webpack and imports-loader

I got this error when I tried to add a jquery library.

{
   test: require("path").resolve("./main/static/src/application.js"),
   loader: 'imports-loader?this=>window,$=jquery!./main/static/src/vendor/jquery-ui/ui/widgets/draggable.js'
}

new webpack.ProvidePlugin({
    $: "jquery",
    jQuery: "jquery",
    'window.jQuery': 'jquery',
    'window.$': 'jquery',
    io: 'socket.io-client',
    _:'underscore',
    moment:"moment",
})

ERROR:

ERROR in jQuery is not defined

It looks like there are a few ways to resolve this, I opted for the expose-loader :

{
  test: require.resolve('jquery'),
  use: [
   'expose-loader?jQuery',
   'expose-loader?$'
  ]
},

See more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM