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

Frustrating warnings when used with webpack #337

Closed
snario opened this issue Jun 2, 2015 · 56 comments · Fixed by #539
Closed

Frustrating warnings when used with webpack #337

snario opened this issue Jun 2, 2015 · 56 comments · Fixed by #539

Comments

@snario
Copy link

snario commented Jun 2, 2015

WARNING in ./~/harmony/~/formidable/lib/incoming_form.js
Critical dependencies:
1:43-50 require function is used in a way, in which dependencies cannot be statically extracted
 @ ./~/harmony/~/formidable/lib/incoming_form.js 1:43-50

WARNING in ./~/harmony/~/formidable/lib/incoming_form.js
Critical dependencies:
1:0-14 the request of a dependency is an expression
 @ ./~/harmony/~/formidable/lib/incoming_form.js 1:0-14

WARNING in ./~/harmony/~/formidable/lib/file.js
Critical dependencies:
1:43-50 require function is used in a way, in which dependencies cannot be statically extracted
 @ ./~/harmony/~/formidable/lib/file.js 1:43-50

WARNING in ./~/harmony/~/formidable/lib/file.js
Critical dependencies:
1:0-14 the request of a dependency is an expression
 @ ./~/harmony/~/formidable/lib/file.js 1:0-14

WARNING in ./~/harmony/~/formidable/lib/querystring_parser.js
Critical dependencies:
1:43-50 require function is used in a way, in which dependencies cannot be statically extracted
 @ ./~/harmony/~/formidable/lib/querystring_parser.js 1:43-50

WARNING in ./~/harmony/~/formidable/lib/querystring_parser.js
Critical dependencies:
1:0-14 the request of a dependency is an expression
 @ ./~/harmony/~/formidable/lib/querystring_parser.js 1:0-14
@tdeheurles
Copy link

Hi, Having same issue.

WARNING in ./~/restify/~/formidable/lib/incoming_form.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/restify/~/formidable/lib/incoming_form.js 1:43-50

WARNING in ./~/restify/~/formidable/lib/file.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/restify/~/formidable/lib/file.js 1:43-50

WARNING in ./~/restify/~/formidable/lib/json_parser.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/restify/~/formidable/lib/json_parser.js 1:43-50

WARNING in ./~/restify/~/formidable/lib/querystring_parser.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/restify/~/formidable/lib/querystring_parser.js 1:43-50

I'm importing restify that uses formidable.
Compiling with webpack generate an issue :

var crypto = require('crypto');
                     ^
TypeError: undefined is not a function

Does it tells something to someone ?
Running var crypto = require('crypto'); in my code does not generate that problem.

@tdeheurles
Copy link

For webpack user, adding :

plugins: [
     new webpack.DefinePlugin({ "global.GENTLY": false })
],

fix the issue.

@quicksnap
Copy link

@tdeheurles Just wanted to say thank you for this. Ran into this when packaging for Electron--was very frustrating.

@quicksnap
Copy link

Looking at the webpack output, this issue could most likely be fixed by changing this line: https://github.com/felixge/node-formidable/blob/master/lib/incoming_form.js#L1
to something like this:

var require = require;
if (global.GENTLY) require = GENTLY.hijack(require);

Adding var require will prevent Webpack from shadowing the actual require with an empty var require; before the if (global.GENTLY).

Would a PR like that be accepted?

Duh.. that would break everything..

EDIT Clicked "Comment" too soon.

@davis
Copy link

davis commented Feb 10, 2016

this is still an issue

@gabrielstuff
Copy link

yup still be, and I confirm :

plugins: [
     new webpack.DefinePlugin({ "global.GENTLY": false })
 ]

Fix it

@benjie
Copy link

benjie commented Dec 2, 2016

Apologies for polluting the thread, but for anyone landing on this and still having issues afterwards who happens to be using superagent, note they have a wiki page saying what to do

[...] you can either use superagent's browser version directly (require('superagent/lib/client')), or fix your Webpack settings:

Add:

plugins.push(new webpack.DefinePlugin({ "global.GENTLY": false }));

and

node: {
  __dirname: true,
}

I also added the following, for good measure:

    alias: {
      'inherits': 'inherits/inherits_browser.js',
      'superagent': 'superagent/lib/client',
      'emitter': 'component-emitter',
    },

This cost me more time than I'd like to admit (oh look at that, it's just gone midnight), so posting here in the hopes it helps someone else since I landed on this page early on in my search...

@tunnckoCore
Copy link
Member

Yea, that definitely a problem of how whole library is written. And kind of sucks. I believe we could change it and improve it for v2 release.

@isaachinman
Copy link

Just ran into this and lost an hour's time trying to figure it out!

@joseSantacruz
Copy link

I have the same issue

@nazmy
Copy link

nazmy commented Apr 21, 2017

Hi @benjie, I'm using superagent and still getting the error after adding the config in the webpack.
I'm using webpack 2.4.1.

Here's my webpack.config snippets:

const plugins = [
    new webpack.DefinePlugin({ "global.GENTLY": false }),
    new webpack.IgnorePlugin(/\.(css|less)$/)
]


module.exports = {
    entry: handlers,
    output: {
        libraryTarget: 'commonjs',
        path: paths.appBuild,
        filename: '[name].js',
    },
    node: {
        __dirname: true,
    },
    externals: [
        'aws-sdk',
    ],
    resolve: {
        fallback: paths.nodePaths,
        extensions: ['.js', '.json', ''],
    },
    module: {
        preLoaders: preLoaders,
        loaders: loaders
    },
    plugins: plugins,
    target: 'node',
    devtool: 'source-map',
}

Warning Notification:

WARNING in ./~/formidable/lib/incoming_form.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/formidable/lib/incoming_form.js 1:43-50

WARNING in ./~/formidable/lib/file.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/formidable/lib/file.js 1:43-50

WARNING in ./~/formidable/lib/json_parser.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/formidable/lib/json_parser.js 1:43-50

WARNING in ./~/formidable/lib/querystring_parser.js
Critical dependencies:
1:43-50 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/formidable/lib/querystring_parser.js 1:43-50

Error Message:

Type Error ---------------------------------------------

     require is not a function

@benjie
Copy link

benjie commented Apr 21, 2017

@nazmy Sorry, can't help other than to suggest you try adding the aliases too?

@brandonmp
Copy link

Been dealing w/ this for a few hours & no luck w/ any of the existing solutions. The problem for me is a bit diff't though: I'm using an electron boilerplate with preconfig'd babel/webpack, and one of the plugins somewhere is doing something strange here.

Basically, babel/webpack/whatever sees this line:

if (global.GENTLY) require = GENTLY.hijack(require);

And I guess considers require to need declaring, so it outputs it as:

var require;if (global.GENTLY) require = GENTLY.hijack(require);

This overwrites global.require & breaks everything else in the file.

Still trying to sort out which plugin is screwing it up, but unfortunately removing plugins one-by-one requires extensive fiddling w/ other things to make the project even start.

It seems like this one line is causing a lot of heartache, esp. since auth0 depends indirectly on this lib.

Does this line need to be required in exactly this way? If it's for testing, can't you set NODE_ENV='test' & wrap this?

@tunnckoCore
Copy link
Member

Does this line need to be required in exactly this way? If it's for testing, can't you set NODE_ENV='test' & wrap this?

Yep, it's about testing I believe. There are many things that should be aligned to the current state of javascript, tooling and work(/dev)flow.

We already have opened the discussion, about converting tests to something like mocha. #415

@russbeye
Copy link

Just got bit by the same very thing as most in here. I see that I have some dependencies on formidable with my Koa stuff:

if (global.GENTLY) require = GENTLY.hijack(require);

Which was transforming into:

var require;if (global.GENTLY) require = GENTLY.hijack(require);

@tdeheurles and @gabrielstuff posted that you can fix this in your webpack config with:

plugins: [ new webpack.DefinePlugin({ "global.GENTLY": false }) ],

This indeed worked. Webpack then outputs:

if (false) require = GENTLY.hijack(require);

Since require then becomes unreachable, it never attempts to redefine require and overwrite the global require.

If this doesn't fix your require issues, I would suggest looking into your compiled webpack packages and search for var require; or something of the like. You want to really investigate whether your global require is being overwritten or not.

@unicornexpat
Copy link

plugins: [ new webpack.DefinePlugin({ "global.GENTLY": false }) ],

This doesn't make the warning go away. However, when i update the required dependency jsdom the warning disappear

@ttqftech
Copy link

ttqftech commented Oct 3, 2021

Thanks to @chouch0u 's solution.
For those who use Koa-body in a vue/cli electron apps, you can also try this:

// vue.config.js
module.exports = {
  pluginOptions: {
    electronBuilder: {
      // List native deps here if they don't work
      externals: ['formidable', 'koa-body'],
    }
  }
}

@ilijapuaca
Copy link

Is there an update on this issue and v2 in general? We've been using "formidable": "2.0.0-canary.20200226.1" as a resolution for a long time now due to this issue, and we now have a problem where one of the libs does not work with the pinned version so we are somewhat stuck figuring out a way forward 😐

@GrosSacASac
Copy link
Contributor

@ilijapuaca Can you try again with version 3 ? It uses import/export syntax so should be better with webpack.

@weaksou
Copy link

weaksou commented Nov 18, 2021

for next js, the config file is different "next.config.js"
you can use the following config:

module.exports = {
  webpack: (config, { isServer, webpack}) => {
    if (!isServer) {
      config.resolve.fallback = {
        fs: false, //here add the packages names and set them to false
      };
    }
    config.plugins.push(new webpack.DefinePlugin({ "global.GENTLY": false }));

    return config;
  },

};

You can add packages that you don't want to include in the client, so you don't get the error:

Module not found: Can't resolve 'fs'

@tunnckoCore
Copy link
Member

@weaksou switch to v2 or v3.

@weaksou
Copy link

weaksou commented Nov 23, 2021

how I'm supposed to do this? I'm new to formidable 😄, thanks.

@tunnckoCore
Copy link
Member

@weaksou check the VERSION_NOTES file. In short, installing formidable as usual now installs the latest v2. The v3 is on v3 dist-tag npm install formidable@v3. The npm dist-tag will change soon too but that doesn't matter that much.

@tunnckoCore
Copy link
Member

Too old. Closing.

@ahoys
Copy link

ahoys commented May 5, 2022

For anyone else who is trying to investigate TypeError: hexoid is not a function and found out that this is the only thread in the entire Internet about the issue: downgrade your superagent (or similar library that uses formidable).

I went from 7 to 6 and that fixed the issue. Looking at the changelog, there's a formidable update mentioned.

@jjmerri
Copy link

jjmerri commented Jun 29, 2022

For anyone else who is trying to investigate TypeError: hexoid is not a function and found out that this is the only thread in the entire Internet about the issue: downgrade your superagent (or similar library that uses formidable).

I went from 7 to 6 and that fixed the issue. Looking at the changelog, there's a formidable update mentioned.

I had to downgrade soap to version 0.43.0 to get this error to go away

@dhruvit-r
Copy link

I found another solution which doesn't require you to downgrade, but this only works if you're working with webpack. Add this to your webpack config file:

const { NormalModuleReplacementPlugin } = require('webpack');

module.exports = {
  ...
  plugins: [
    ...
    new NormalModuleReplacementPlugin(/^hexoid$/, require.resolve('hexoid/dist/index.js')),
  ]
}

@eduviereIsrael
Copy link

yup still be, and I confirm :

plugins: [
     new webpack.DefinePlugin({ "global.GENTLY": false })
 ]

Fix it

Good afternoon, Please where am I supposed to input the above code?

@skaraudio
Copy link

skaraudio commented Sep 22, 2022

I found another solution which doesn't require you to downgrade, but this only works if you're working with webpack. Add this to your webpack config file:

const { NormalModuleReplacementPlugin } = require('webpack');

module.exports = {
  ...
  plugins: [
    ...
    new NormalModuleReplacementPlugin(/^hexoid$/, require.resolve('hexoid/dist/index.js')),
  ]
}

This worked for Next JS :)

    if (!isServer) {
      config.resolve.fallback.fs = false
      config.resolve.fallback.dns = false
      config.resolve.fallback.net = false
    }

    config.plugins.push(
        new NormalModuleReplacementPlugin(/^hexoid$/, require.resolve('hexoid/dist/index.js')),
    );
    return config

@Josh-a-e
Copy link

Having recently come across this same issue, I eventually discovered this fixed it

image

@PSoltes
Copy link

PSoltes commented Mar 13, 2023

I tried build a clean new project only with express and formidable, it works. But when I build a electron project by Vue/Cli and Vue-electron try require formidable on main.js (or background.js ) it shows up this error:

App threw an error during load
TypeError: hexoid is not a function

Must be something wrong with webpack or vue or electrons build system.

And I find the solution, Add formidable to externals on vue.config.js under the electronBuilder option. Anyone try to use formidable at vue-electron project should try this.

// vue.config.js
module.exports = {
  pluginOptions: {
    electronBuilder: {
      // List native deps here if they don't work
      externals: ['formidable'],
    }
  }
}

webpack config also has externals prop, just mentioning

@ca-santiago
Copy link

ca-santiago commented Apr 9, 2023

I found this issue while using webpack for a server application, I used webpack-node-externals as externals: [webpackNodeExternals()], docs here. This allows the bundle file to has node dependencies included.

For me the issue was the same, but in a different context, hope this help more than one.

@oyatek
Copy link

oyatek commented May 13, 2024

For webpack user, adding :

plugins: [
     new webpack.DefinePlugin({ "global.GENTLY": false })
],

fix the issue.

thank you so much. I would've never found this by myself, Google/StackOF/GH_Copilot had no clue how to fix it. Only you did!

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

Successfully merging a pull request may close this issue.