Git Product home page Git Product logo

Comments (17)

andris9 avatar andris9 commented on August 20, 2024 34

This change would break browserify which is more used than webpack. I'm willing to change the code to support webpack as well but only if it doesn't break anything existing.

from encoding.

andris9 avatar andris9 commented on August 20, 2024 19

This module is meant for Node only, do not use it with webpack if it doesn't work

from encoding.

jimpick avatar jimpick commented on August 20, 2024 14

IgnorePlugin didn't work for me, when I used it, webpack put in some code that throws an error. I did this instead in plugins:

new webpack.NormalModuleReplacementPlugin(//iconv-loader$/, 'node-noop')

I needed to install the node-noop npm module.

from encoding.

andris9 avatar andris9 commented on August 20, 2024 7

This behavior with require as an expression is intentional to be able to load iconv in environments where it is supported and fall back to iconv-lite where it is not. Webpack support is not a priority.

from encoding.

silvenon avatar silvenon commented on August 20, 2024 3

This works:

  module: {
    exprContextRegExp: /$^/,
    exprContextCritical: false,
    loaders: [/*...*/]
  }

It invalidates all require(expr) cases, i.e. this one, just as the Universe intended. Stolen from webpack/webpack#198 (comment).

from encoding.

silvenon avatar silvenon commented on August 20, 2024 2

whatwg-fetch does not work in Node, which is why isomorphic-fetch exists. This issue is probably most common when you're trying to compile your tests with webpack before running them, so you have good control over how some special stuff like CSS imports will be handled.

Eventually I realized that doing that is an overkill and I can just use require.extensions to nullify those imports.

from encoding.

rublev avatar rublev commented on August 20, 2024 2

@silvenon

Eventually I realized that doing that is an overkill and I can just use require.extensions to nullify those imports.

How?

from encoding.

iamdanielyin avatar iamdanielyin commented on August 20, 2024 1

Use the 'whatwg-fetch' instead of 'node-fetch'

from encoding.

hh9527 avatar hh9527 commented on August 20, 2024

I use this module in node env. With webpack, the server side application can be packaged in one js file with only required source files included.

from encoding.

hh9527 avatar hh9527 commented on August 20, 2024

Currently, webpack is ok except the above warning.

But change these 2 lines

    var iconv_package = 'iconv';
    Iconv = require(iconv_package).Iconv;

to

    Iconv = require('iconv').Iconv;

will allow user to avoid the warning.

from encoding.

hh9527 avatar hh9527 commented on August 20, 2024

OK, thank you.

There is a way to do that:

Iconv = require('./iconv-loader');

and

// file: iconv-loader.js
var pkg = 'iconv';
module.exports = require(pkg);

and then, user can use webpack.IgnorePlugin to ignore /\/iconv-loader$/

from encoding.

andris9 avatar andris9 commented on August 20, 2024

Updated code to load Iconv as you suggested. Released as v0.1.12

from encoding.

hh9527 avatar hh9527 commented on August 20, 2024

Thank you!

from encoding.

silvenon avatar silvenon commented on August 20, 2024

Won't this cause an error as soon as it's run with Node? I'm getting this:

Error: Cannot find module "./iconv-loader"

I think it's meant only for requires inside a try...catch block?

from encoding.

silvenon avatar silvenon commented on August 20, 2024

@jimpick that's much cleaner, thanks 👍

from encoding.

silvenon avatar silvenon commented on August 20, 2024

@rublev sorry for a much too late reply, but if you're using Jest, you can configure moduleNameMapper. Otherwise you can use ignore-styles or something like that.

from encoding.

imankeeth avatar imankeeth commented on August 20, 2024

new webpack.NormalModuleReplacementPlugin(//iconv-loader$/, 'node-noop')

Is the double slash // before iconv-loader intended?

from encoding.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.