davidstutz / bootstrap-multiselect

JQuery multiselect plugin based on Twitter Bootstrap.
https://davidstutz.github.io/bootstrap-multiselect/
Other
3.67k stars 1.98k forks source link

Module not found: Error: Can't resolve 'knockout' in '~/node_modules/bootstrap-multiselect/dist/js' #1123

Open sourav-prescriber-360 opened 4 years ago

sourav-prescriber-360 commented 4 years ago

Facing this issue with ^0.9.13-1:

ERROR in ./~/bootstrap-multiselect/dist/js/bootstrap-multiselect.js Module not found: Error: Can't resolve 'knockout' in '/Users/Downloads/projectX/node_modules/bootstrap-multiselect/dist/js' @ ./~/bootstrap-multiselect/dist/js/bootstrap-multiselect.js 51:8-47 @ ./public/javascripts/datatable-gc.js @ ./public/javascripts/speciesTree.js @ ./public/javascripts/render_viewer.js @ multi webpack-hot-middleware/client ./public/javascripts/render_viewer.js

7iomka commented 4 years ago

Same issue after upgrade to latest version. Any ideas?

sourav-prescriber-360 commented 4 years ago

No solution yet, all references are up to date too.

adamcopley commented 4 years ago

I have also had this in conjunction with WARNING in ./node_modules/bootstrap-multiselect/dist/js/bootstrap-multiselect.js 48:48-55 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

I notice in the changelog for this package that some work has been done with regards to using requirejs or require etc, I don't understand it myself as I'm not sure what changes were made and for what purpose. But can see the pattern

@davidstutz - is there any reason why the devDependencies list in package.json on tag 0.9.15 is different to what you get when you download it from NPM? i.e. knockout is not included in the repos package.json anywhere, but when you download it from npm, it has knockout: "*" in there.

HoiDam commented 4 years ago

any update?

theory-of-soul commented 4 years ago

You can try to add these rows to webpack.config.js

plugins: [
  new webpack.ProvidePlugin({
      jQuery: 'jquery',
      'window.jQuery': 'jquery',
  })
],
...
resolve: {
    ...
    alias: {
      // path to your jquery in node_modules
      'jquery': path.resolve(__dirname, 'node_modules/jquery/dist/jquery'),
    }
},
...
module: {
    rules: [
      ...,
      {
        test: require.resolve('bootstrap-multiselect/dist/js/bootstrap-multiselect'),
        use: 'imports-loader?define=>false,this=>window',
      },
      ...
]

it works for me

theandrewlane commented 4 years ago

Any updates on this one?

Lukom commented 3 years ago

For Ruby on Rails project with webpacker I had to add this to environment.js to make it work:

environment.loaders.append('this-window', {
  test: /bootstrap-multiselect/,
  use: [
    {
      loader: 'imports-loader',
      options: {
        wrapper: 'window',
        additionalCode: 'var define = false;',
      },
    },
  ],
});

+ yarn add imports-loader. It still shows two warnings on compilation but works.

aroshasum commented 3 years ago

I installed bootstrap-multiselect 0.9.15 and I got the error Module not found: Can't resolve 'knockout' in '/Users/aroshasumanaweera/node_modules/bootstrap-multiselect/dist/js. My workaround was to install knockout for the sake of dependency, which worked!!. Run npm i knockout