question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not working with Karma and Webpack 4

See original GitHub issue

Hi,

I’ve a strange bug. All works correctly when I run my application in production, but I can’t run my unit tests because of your module… Removing all require('iconv-lite') in my code resolve the problem.

I’m using Webpack 4, Karma 3, ES6.

This is the error I get:

Electron 3.0.2 (Node 10.2.0) ERROR
  {
    "message": "Uncaught TypeError: __webpack_require__(...) is not a function\nat webpack:///app/node_modules/iconv-lite/lib/index.js:144:27 <- index.js:58520:48\n\nundefined",
    "str": "Uncaught TypeError: __webpack_require__(...) is not a function\nat webpack:///app/node_modules/iconv-lite/lib/index.js:144:27 <- index.js:58520:48\n\nundefined"
  }

Have you any Idea of what this could be ? Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:29 (9 by maintainers)

github_iconTop GitHub Comments

44reactions
popodcommented, Oct 23, 2018

As @Feverqwe said in #205 : adding

{
  test: /node_modules[\/\\](iconv-lite)[\/\\].+/,
  resolve: {
    aliasFields: ['main']
  }
}

to the webpack module.rules solve my problem. Thanks for the workaround !

But I think that @whitehat101 PR #203 is a better solution and hope it will be merged soon.

19reactions
rememberjackcommented, Oct 8, 2018

I ran into the same issue in an electron environment (using vue-cli-plugin-electron-builder).

I believe the problem originates from these configurations:

  1. When building electron app, webpack is configured to use target ‘web’ or ‘electron-renderer’.
  2. This webpack target in turn takes browser property into account. In this case, webpack ignores streams.js and extend-node.js from bundling because they are set to false in the browser property in the package.json.
  3. index.js checks for node process and environment to determine if it is in a node environment. But in the case of electron, it is both a browser environment and a node environment. So iconv thinks it is in a node environment when the bundler thinks it is bundling for a web environment. This leads to __webpack_require__(...) is not a function error because streams.js is never bundled.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Autowatch not working with karma-webpack on karma version ...
Fix. Downgrade Karma to 3.1.4 version fixed the problem.
Read more >
Can anyone provide a webpack4 & Karma configuration that ...
I recently upgraded to Webpack4 and I am running into issues where karma start will run my webpack build and then do nothing....
Read more >
karma-webpack - npm
Start using karma-webpack in your project by running `npm i karma-webpack`. ... karma-webpack. 4.0.0-rc.6 • Public • Published 4 years ago.
Read more >
TypeScript starter project w/ Webpack 4, Karma, Jasmine
This tutorial showcases a starter project for people who want to use TypeScript w/ a stater project already setup to deploy to browsers ......
Read more >
KJS: Resources are not available when running Karma tests
The core of the issue seems to be that during development, files from the resources directory are served by webpack-dev-server, while during Karma...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found