ERROR TypeError: "bloom_filters__WEBPACK_IMPORTED_MODULE_2__ is not a constructor"
offline-pixel opened this issue · 1 comments
In angular project
Step 1 : run npm install bloom-filters --save
Step 2: Add "node_modules/bloom-filters/bloom-filters.js" in angular.json
Step 3: Import in component file as import * as BloomFilter from 'bloom-filters'
my package.json is
{
"name": "",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~7.1.0",
"@angular/cdk": "~7.1.0",
"@angular/common": "~7.1.0",
"@angular/compiler": "~7.1.0",
"@angular/core": "~7.1.0",
"@angular/forms": "~7.1.0",
"@angular/platform-browser": "~7.1.0",
"@angular/platform-browser-dynamic": "~7.1.0",
"@angular/router": "~7.1.0",
"@types/axios": "^0.14.0",
"aes-js": "^3.1.2",
"angular-filepond": "^1.0.5",
"bloom-filters": "^0.5.2",
"chart.js": "^2.7.3",
"core-js": "^2.5.4",
"d3": "^5.7.0",
"datatables.net": "^1.10.19",
"datatables.net-dt": "^1.10.19",
"echarts": "^4.2.0-rc.2",
"js-sha256": "^0.9.0",
"jssha": "^2.3.1",
"ng2-charts": "^1.6.0",
"ng2-pdf-viewer": "^5.2.3",
"ng2-toastr": "^4.1.2",
"ngx-echarts": "^4.1.0",
"ngx-extended-pdf-viewer": "^0.9.14",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},let filter = new BloomFilter(15, 0.01)
"devDependencies": {
"@angular-devkit/build-angular": "~0.11.0",
"@angular/cli": "~7.1.2",
"@angular/compiler-cli": "~7.1.0",
"@angular/language-service": "~7.1.0",
"@schematics/angular": "~7.1.0",
"@types/echarts": "^4.1.3",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^8.9.5",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.1.6"
}
}
GOT the title error
Solution might be
1.
2. how to import node npm module in angular project
You are not using the package like it should be used. The bloom-filter
package exposes several data structures. Thus, with import * as BloomFilter from 'bloom-filters'
, you are importing all of these structures and not the BloomFilter
one.
Futhermore, this is an issue related to your usage of Webpack, and not to this package.
You should follow the README more closely. The following code should work in your case.
// only import the BllomFilter datastructure
import { BloomFilter } from 'bloom-filters'
let filter = new BloomFilter(15, 0.01)
// alternatively, create a Bloom Filter from an array with 1% error rate
filter = BloomFilter.from([ 'alice', 'bob' ], 0.01)
// add some value in the filter
filter.add('alice')
filter.add('bob')
// lookup for some data
console.log(filter.has('bob')) // output: true
console.log(filter.has('daniel')) // output: false
// print false positive rate (around 0.01)
console.log(filter.rate())