Skip to content
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

Warnings with webpack. #16

Closed
hh9527 opened this issue Dec 22, 2015 · 17 comments
Closed

Warnings with webpack. #16

hh9527 opened this issue Dec 22, 2015 · 17 comments

Comments

@hh9527
Copy link

hh9527 commented Dec 22, 2015

WARNING in d:/dws/projects/febs/febs/~/encoding/lib/encoding.js
Critical dependencies:
9:12-34 the request of a dependency is an expression
 @ d:/dws/projects/febs/febs/~/encoding/lib/encoding.js 9:12-34

Related code: https://github.com/andris9/encoding/blob/master/lib/encoding.js#L9

Please dont try to fool webpack, users can use webpack.IgnorePlugin to prevent loading of 'iconv'.

@andris9
Copy link
Owner

andris9 commented Dec 22, 2015

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

@andris9 andris9 closed this as completed Dec 22, 2015
@hh9527
Copy link
Author

hh9527 commented Dec 22, 2015

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.

@andris9
Copy link
Owner

andris9 commented Dec 22, 2015

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.

@hh9527
Copy link
Author

hh9527 commented Dec 22, 2015

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.

@andris9
Copy link
Owner

andris9 commented Dec 22, 2015

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.

@hh9527
Copy link
Author

hh9527 commented Dec 22, 2015

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$/

@andris9
Copy link
Owner

andris9 commented Dec 23, 2015

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

@hh9527
Copy link
Author

hh9527 commented Dec 23, 2015

Thank you!

@silvenon
Copy link

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?

@silvenon
Copy link

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).

@jimpick
Copy link

jimpick commented Mar 4, 2016

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.

jimpick added a commit to jimpick/lambda-scraper-queue that referenced this issue Mar 4, 2016
@silvenon
Copy link

silvenon commented Mar 4, 2016

@jimpick that's much cleaner, thanks 👍

@iamdanielyin
Copy link

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

@silvenon
Copy link

silvenon commented Jun 19, 2016

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.

@rublev
Copy link

rublev commented Apr 6, 2017

@silvenon

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

How?

@silvenon
Copy link

silvenon commented Jul 6, 2017

@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.

@imankeeth
Copy link

imankeeth commented Mar 17, 2019

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants