ng2-handsontable: TypeError: require is not a function
Hello,
I had a working ng2-handsontable on production but with a latest deploy, I’m getting a type error at (handsontable.js:46). Is there any dependency that I’m missing? or any compiler options that I should be looking at ?

Following is my package.json file -
"@angular/animations": "^4.1.3",
"@angular/common": "^4.1.3",
"@angular/compiler": "^4.1.3",
"@angular/compiler-cli": "^4.1.3",
"@angular/core": "^4.1.3",
"@angular/forms": "^4.1.3",
"@angular/http": "^4.1.3",
"@angular/platform-browser": "^4.1.3",
"@angular/platform-browser-dynamic": "^4.1.3",
"@angular/platform-server": "^4.1.3",
"@angular/router": "^4.1.3",
"@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.26",
"@types/node": "^6.0.73",
"angular-tree-component": "^3.7.3",
"bootstrap": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.0.0-alpha.6.tgz",
"core-js": "^2.4.1",
"jquery": "^3.2.1",
"karma-chrome-launcher": "^2.1.1",
"moment": "^2.18.1",
"ng-bootstrap": "^1.6.3",
"ng2-handsontable": "^1.0.3",
"ng2-translate": "^5.0.0",
"ngx-bootstrap": "^1.6.6",
"ngx-contextmenu": "^1.2.0",
"rxjs": "^5.4.0",
"survey-angular": "^0.12.15",
"ts-helpers": "^1.1.1",
"typescript": "2.3.4",
"zone.js": "^0.7.2",
"ng2-toastr": "^4.1.0"
},
"devDependencies": {
"@angular/cli": "^1.0.0",
"@angular/compiler-cli": "^4.1.3",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "^4.3.0",
"typescript": "2.3.4"
}```
Thanks
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 25
@HIMISOCOOL @renehamburger
The branch has been merged into master that fixes this. Just need a new release so that we can get it in NPM. 😃 Please?
There are a few (hopefully minor) issues that showed up in the quality check yesterday. They need to be fixed first before we can push it to npm. If anyone in this thread has got time to help with this, please let me know. Otherwise I should get this done by the weekend the latest.
I had a play around with this yesterday and was gonna log this on the weekend when I had time. It’s because of the latest version of angular cli (1.3.0) and therefore the latest version of the compiler + webpack. AFAIK require was always undefined but now it’s a problem.
@nachikettalwalkar You could try using the 1.2.8 version of the cli if you need it working for now. To do that change your @angular/cli to ~1.2.8 (rather than ^1.0.0)
@renehamburger Thanks for all your effort and work to resolve this issue and for v 2.0! Can you please publish this release to NPM or let me know how I can use it?
I tried updating my package.json to “ng2-handsontable”: “github:valor-software/ng2-handsontable#2.0.0” (similar to how you used the feature branch/commit from handsontable before they release their update), but this did not add ng2-handsontable to my node_modules. I also tried “npm i github:valor-software/ng2-handsontable#2.0.0” and that added “ng2-handsontable-base”: “github:valor-software/ng2-handsontable#2.0.0” to my package.json and “ng2-handsontable-base” in my node_modules. I couldn’t figure out how use this and when I compared the files and package.json in ng2-handsontable and ng2-handsontable-base, they were very different. It seems like there’s a build process that happens when (or before) you publish to NPM.
Looking forward to your help, resolving this issue 100% and updating Angular CLI.
Ps. I’m a very new developer with < 1 year experience so sorry if the answer is simple or obvious.
The required PR at handsontable has been merged (but not yet released). I’ve updated the feature branch handsontable-update to use that commit, which works fine now. Feel free to use that branch to test it in your environment. We will release this once handsontable has done a new release, too.
Hello, I have a similar problem:
My package.json file is:
"dependencies": { "@angular/common": "4.1.3", "@angular/compiler": "4.1.3", "@angular/compiler-cli": "4.1.3", "@angular/core": "4.1.3", "@angular/forms": "4.1.3", "@angular/http": "4.1.3", "@angular/platform-browser": "4.1.3", "@angular/platform-browser-dynamic": "4.1.3", "@ionic-native/core": "3.12.1", "@ionic-native/keyboard": "3.12.1", "@ionic-native/splash-screen": "3.12.1", "@ionic-native/status-bar": "3.12.1", "@ionic/storage": "2.0.1", "@types/big.js": "0.0.31", "@types/handsontable": "0.31.1", "big.js": "^3.1.3", "ionic-angular": "3.6.0", "ionicons": "3.0.0", "ng2-handsontable": "1.0.3", "ng2-img-cropper": "^0.9.0", "rxjs": "5.4.0", "sw-toolbox": "3.6.0", "zone.js": "0.8.12" }, "devDependencies": { "@ionic/app-scripts": "2.1.4", "ionic": "3.9.1", "pug": "^2.0.0-rc.2", "typescript": "2.3.4" }If I change the
"@ionic/app-scripts": "2.1.4"to"@ionic/app-scripts": "1.3.7"does not throw this error.Any idea why it marks that mistake?
@josehenriqueventura You still have
"@angular/cli": "^1.2.6"with a^, that definitely caused me the problems. My package.json has"@angular/cli": "~1.2.8". Glad its working for u now.