Skip to content

iconv-loader webpack issue #18

@iongion

Description

@iongion

As you are aware, this works if library found is iconv, but what if the fallback is on iconv-lite ?

'use strict';

var iconv_package;
var Iconv;

try {
    // this is to fool browserify so it doesn't try (in vain) to install iconv.
    iconv_package = 'iconv';
    Iconv = require(iconv_package).Iconv;
} catch (E) {
    // node-iconv not present
}

module.exports = Iconv;

webpack output

WARNING in ./~/encoding/lib/iconv-loader.js
9:12-34 Critical dependency: the request of a dependency is an expression`

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:

'use strict';
module.exports = require('iconv-lite').Iconv;

But it will probably blow-apart when the dep is iconv and not iconv-lite, I don't know how to solve this only for my project.

What if the wrapper is more like this ?

'use strict';
var Iconv = null;
// this is to fool browserify so it doesn't try (in vain) to install iconv.
try {
  Iconv = require('iconv-lite').Iconv;
} catch (LE) {
  try {
    Iconv = require('iconv').Iconv;
  } catch (E) {
    // node-iconv not present
  }
}
module.exports = Iconv;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions