-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iconv-loader webpack issue #18
Comments
I have the same issue |
Same issue here |
Thank you, it worked for me! |
@pepihasenfuss beware, it might still create issues if you use things such as
CORRECTION The exception I get is ignorable, due to this code:
In the fallback(first try..catch), it should not be Until the author has time for this, I have made a simple patch in vanilla JS, that you can call in the postinstall, save this in a // IIFE
(function() {
'use strict';
// node
var fs = require('fs');
var path = require('path');
// Patch encoding module due to iconv issues -> make it use iconv-lite
(function() {
var PATCH_VERSION = '0.1.12';
var PATCH_MODULE = 'encoding';
var PATCH_REASON = 'Use iconv-lite instead of iconv, helpful for webpack bundling';
console.log('patching `%s`(%s) module', PATCH_MODULE, PATCH_VERSION);
var pathToModule = path.join(path.dirname(__dirname), 'node_modules', PATCH_MODULE);
var pathToModulePackage = path.join(pathToModule, 'package.json');
var pathToModulePatchedFile1 = path.join(pathToModule, 'lib/iconv-loader.js');
var pathToModulePatchedFile2 = path.join(pathToModule, 'lib/encoding.js');
var moduleInfo = require(pathToModulePackage);
if (moduleInfo.version !== PATCH_VERSION) {
console.error(
'patching `encoding` failed - expected `%s` but detected `%s`',
PATCH_VERSION,
moduleInfo.version
);
process.exit(1);
}
var contents;
if (fs.existsSync(pathToModulePatchedFile1)) {
contents = [
'\'use strict\';',
'module.exports = require(\'iconv-lite\');',
'',
].join('\n');
fs.writeFileSync(pathToModulePatchedFile1, contents);
} else {
console.error('patching `%s` failed because the file does not exist in', PATCH_MODULE, pathToModule);
process.exit(1);
}
if (fs.existsSync(pathToModulePatchedFile2)) {
contents = fs.readFileSync(pathToModulePatchedFile2).toString();
contents = contents.replace('console.error(E);','');
fs.writeFileSync(pathToModulePatchedFile2, contents);
} else {
console.error('patching `%s` failed because the file does not exist in', PATCH_MODULE, pathToModule);
process.exit(1);
}
console.log('patching `%s`, reason: `%s` - completed', PATCH_MODULE, PATCH_REASON);
})();
})(this); In your
|
@iongion Correct path is: ...
var pathToModule = path.join(__dirname, 'node_modules', PATCH_MODULE);
...
|
it worked for me changing the content of the file 'iconv-loader.js' to : thank u very much |
Thanks @iongion , your solution (...require('iconv-lite').Iconv) stops the "Critical dependency: the request..." alert, but there is another effect that remains: webpack keeps adding the entire iconv-lite to the final bundle, which is 493kb. (angular cli project) :( Any idea on this? |
@aleixsuau It depends on your use case, you might not be able to avoid it because it is really needed by your project requirements, you could give it a try as it is described here https://remarkablemark.org/blog/2017/02/25/webpack-ignore-module |
Why not just add |
@andriy-f this basically mean not using this pliugin which cannot be the solution for using this plugin |
@iongion Thank you for the patch 👍 I am using it in a yarn workspace environment, so I've updated the resolution of the package in the script with
Here is the full updated script:// IIFE
(function() {
'use strict';
// node
var fs = require('fs');
var path = require('path');
// Patch encoding module due to iconv issues -> make it use iconv-lite
(function() {
var PATCH_VERSION = '0.1.12';
var PATCH_MODULE = 'encoding';
var PATCH_REASON = 'Use iconv-lite instead of iconv, helpful for webpack bundling';
console.log('patching `%s`(%s) module', PATCH_MODULE, PATCH_VERSION);
var pathToModule = path.dirname(require.resolve(PATCH_MODULE + '/package.json'));
var pathToModulePackage = path.join(pathToModule, 'package.json');
var pathToModulePatchedFile1 = path.join(pathToModule, 'lib/iconv-loader.js');
var pathToModulePatchedFile2 = path.join(pathToModule, 'lib/encoding.js');
var moduleInfo = require(pathToModulePackage);
if (moduleInfo.version !== PATCH_VERSION) {
console.error(
'patching `encoding` failed - expected `%s` but detected `%s`',
PATCH_VERSION,
moduleInfo.version
);
process.exit(1);
}
var contents;
if (fs.existsSync(pathToModulePatchedFile1)) {
contents = [
'\'use strict\';',
'module.exports = require(\'iconv-lite\');',
'',
].join('\n');
fs.writeFileSync(pathToModulePatchedFile1, contents);
} else {
console.error('patching `%s` failed because the file does not exist in', PATCH_MODULE, pathToModule);
process.exit(1);
}
if (fs.existsSync(pathToModulePatchedFile2)) {
contents = fs.readFileSync(pathToModulePatchedFile2).toString();
contents = contents.replace('console.error(E);','');
fs.writeFileSync(pathToModulePatchedFile2, contents);
} else {
console.error('patching `%s` failed because the file does not exist in', PATCH_MODULE, pathToModule);
process.exit(1);
}
console.log('patching `%s`, reason: `%s` - completed', PATCH_MODULE, PATCH_REASON);
})();
})(this); |
me too! |
any update on this? will this be fixed soon? |
Second on this petition |
Thanks a lot! This worked for me when I had the same issue with Sentry for Electron I'll add a note for others who will find this =)
|
Just wondering, why is this module even used by anyone? The goal for this module was to load compiled node-iconv and if not available, fallback to iconv-lite. If you never need node-iconv, then you could go straight to iconv-lite and skip this wrapper module entirely. |
Absolutely no idea =) My case the warning appeared when I started to use deep import in https://github.com/getsentry/sentry-electron Seems that the problem exists for a while there |
It appears that this module is not used for its original purpose anymore anywhere so I guess I could just remove the iconv thing and keep iconv-lite like a normal dependency, so there would be no loader shenanigans needed. |
fixed in v0.1.13 |
As you are aware, this works if library found is
iconv
, but what if the fallback is oniconv-lite
?webpack output
I am using webpack more like a bundler to ship single-file functions at AWS lambda for execution(there is no npm available there) and to also bundle dependencies(binary files are bundled too, by a manual script I maintain)
This change removes any issues:
But it will probably blow-apart when the dep is
iconv
and noticonv-lite
, I don't know how to solve this only for my project.What if the wrapper is more like this ?
The text was updated successfully, but these errors were encountered: