Closed snario closed 2 years ago
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.
For webpack user, adding :
plugins: [
new webpack.DefinePlugin({ "global.GENTLY": false })
],
fix the issue.
@tdeheurles Just wanted to say thank you for this. Ran into this when packaging for Electron--was very frustrating.
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.
this is still an issue
yup still be, and I confirm :
plugins: [
new webpack.DefinePlugin({ "global.GENTLY": false })
]
Fix it
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...
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.
Just ran into this and lost an hour's time trying to figure it out!
I have the same issue
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
@nazmy Sorry, can't help other than to suggest you try adding the aliases too?
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?
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
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.
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
Remove target: 'node' from your webpack config
Is a code fix possible instead of using webpack config rules to silence the issue? What about just deleting if (global.GENTLY) require = GENTLY.hijack(require);
lines?
Just want to say this issue = a whole day lost, especially because how it was obfuscated on Serverless + AWS Lambda.
@kedarv, we can just delete them, for now. It's a weird thing for the testing. We need rewrite of the whole testing anyway.
@sverraest Sorry about that, i've experienced that too... sadly, yup, that's the case for now. The v2 may come soon, or probably after the holidays... it just depends.
You all can support us - financially or by contributing (I'll push contributing.md soon) to the tests codebase after #531 is merged. We are only 2 devs pushing a lot of updates recently.
Apparently this also affects rollup (I don't use webpack but my bug #538 was marked a duplicate of this)
Yea. Kind of normal with this codebase which for testing purposes is hijacking globals... and the tests are awful. But I will work on this until the end of month hopefully.
For what it's worth, you can fork this library and remove the offending lines and force your project to use your fork until this is fixed in upstream
@kedarv PRs are welcome too. #415
Since which version is this fixed?
@danielo515, none yet. It's only on master. You can do
npm install node-formidable/node-formidable#master
Sadly I can not, this library is an indirect dependency. What I ended doing is not using the library at all. I was lucky and I was possible this time
Why not release a patch version with the fix?
@kedarv because we can't. We did merged a ton of stuff and there's possible breaking changes.
Once we release v2, the release flow will be a lot smoother and easier.
@kedarv @joseSantacruz @danielo515 @mikemaccana @sverraest @ashgaliyev @dev101 @domaslasauskas @cc9226b77c @edorivai @frol @foxxtrot @ryb73 @catamphetamine @tdeheurles
Please try npm install formidable@canary
- preview of v2. The API is almost the same, check the docs or open new issue if there's some problem.
Thanks.
I've created a repository with node-auth0 already bundled for anyone to use in their own project to avoid any issues with formidable and similar errors. https://github.com/patrykkrawczyk/node-auth0-bundle
Just get the node-auth0-bundle.js
file from the dist
directory, place it in your project and reference it with import/require statements as such:
import { ManagementClient } from './libs/node-auth0-bundle'
import { AuthenticationClient } from './libs/node-auth0-bundle'
Okay. But it's a lot better to just switch to the canary v2. There are (almost*) no breaking changes.
* except if you are adding options to the instance, which is a very bad practice anyway
@tunnckoCore , it appears your commit to add hexoid
revived a similar problem.
For all folks reading, 2.0.0-canary.20200226.1
was the last stable version.
"formidable": "^2.0.0-canary.20200504.1"
App threw an error during load
TypeError: hexoid is not a function
Is not a function again. Still not works.
What is the solution ?
How this is even possible?! No new version on our side, nothing touched, and plus we have pinned version in deps list...
@chouch0u try installing hexoid@1.0.0
in your app alongside formidable.
Some strange things are happening lately.
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-electon 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.
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'],
}
}
}
Yep, Webpack has some issue with us and can't bundle Formidable :rofl:
Cool that you find some solution! :)
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'],
}
}
}
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 😐
@ilijapuaca Can you try again with version 3 ? It uses import/export syntax so should be better with webpack.
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'
@weaksou switch to v2 or v3.
how I'm supposed to do this? I'm new to formidable 😄, thanks.
@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.
Too old. Closing.
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.
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
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')),
]
}