krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
18.15k stars 767 forks source link

Fuse is not a constructor #567

Closed mikeymckay closed 3 years ago

mikeymckay commented 3 years ago

I am requiring fuse:

Fuse = require('fuse.js')

When I run it in locally in node it works fine. Then in order to deploy it to an AWS Lambda function I package it up with webpack. The error that I get from the AWS logs is:

Fuse is not a constructor.

I've seen people posting similar errors with Fuse and angular, which also uses webpack. So I am guessing that it is the webpack step that is breaking stuff. Any suggestions on how to resolve this?

mikeymckay commented 3 years ago

Confirmed that this is a webpack issue and not something to do with the AWS environment. But I still haven't figured it out what I need to do in webpack to make it work. Here is my webpack.js file:

const path = require('path');

module.exports = {
  entry: './index.coffee',

  output: {
    libraryTarget: 'commonjs',
    path: path.resolve(__dirname, 'dist'),
    publicPath: '',
    filename: 'index.js'
  },
  mode: 'production',
  optimization: {
    minimize: false,
  },
  target: 'node',
  node: false,
  module: {
    rules: [
      {
        test: /\.coffee$/,
        loader: 'coffee-loader',
      },
    ],
  },
  resolve: {
    extensions: [ '.js', '.coffee' ]
  }
};
github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

TimShilov commented 2 years ago

For anyone encountering this issue, I managed to solve this error by simply replacing the require part from this:

const Fuse = require("fuse.js");

to this:

const Fuse = require("fuse.js").default;