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

Compile error the code inside var crypto = require('crypto'); TypeError: require is not a function #452

Closed
WinterMain opened this issue Nov 14, 2017 · 11 comments

Comments

@WinterMain
Copy link

WinterMain commented Nov 14, 2017

When I use formidable the complier prompt below error. After I removing using of formidable, it will run OK.

/Users/yanglidong/Documents/Work/Company/Git/YLD/samyoc/dist/server/server.js:254224
var crypto = require('crypto');
^

TypeError: require is not a function
at Object.map../file (/Users/yanglidong/Documents/Work/Company/Git/YLD/samyoc/dist/server/server.js:254224:15)

@tushar-singh
Copy link

tushar-singh commented Dec 18, 2017

I ran into the same issue with a library that has formidable as dependency.
I'm gonna assume you're using webpack to build it. In which case this is the fix

add this to webpack config:

externals: [
        {
            formidable: 'commonjs formidable',
        },
],

webpack will then skip over formidable and leave require('formdiable') intact – making node load it when you execute bundle, which seems to work

@raphaelsoul
Copy link

@tushar-singh not work with webpack4

@tunnckoCore
Copy link
Member

tunnckoCore commented Jun 24, 2018

@raphaelsoul, check migration guides.

Closing since it's not a problem here, but outside this lib and probably in the tooling. We working on improving docs and in near future it may be better.

@aiyld thanks for the report. If it is still a problem, feel free to open new issue.

Cheers.

@tunnckoCore tunnckoCore added bug and removed bug labels Jun 24, 2018
@rw3iss
Copy link

rw3iss commented Jul 29, 2019

Still an issue with webpack 4. Using externals entry doesn't work. Can't use the package.

@astonishqft
Copy link

I ran into the same issue with a library that has formidable as dependency.
I'm gonna assume you're using webpack to build it. In which case this is the fix

add this to webpack config:

externals: [
        {
            formidable: 'commonjs formidable',
        },
],

webpack will then skip over formidable and leave require('formdiable') intact – making node load it when you execute bundle, which seems to work

thanks! it works!

@im-danwu
Copy link

Hmm on webpack 4.29.6 and up and adding the externals works

@Diokuz
Copy link

Diokuz commented Feb 18, 2020

2020, and the issue is still here :(

Have to additionally configure all my projects.

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

Looks like it wont work after #539 ?

@tunnckoCore
Copy link
Member

tunnckoCore commented Feb 19, 2020

@Diokuz did you try canary dist-tag? Everything merged, fixed and introduced since 1.2.1 from before years, is in there. Codebase is refactored and gently is completely removed.

@Diokuz
Copy link

Diokuz commented May 21, 2020

No, I didnt, because it is our subdependency. But the problem is still there in the latest version 1.2.2.

@tunnckoCore
Copy link
Member

tunnckoCore commented May 23, 2020

No, I didnt, because it is our subdependency.

Oh, I see. ;/

But the problem is still there in the latest version 1.2.2.

Yup. It was just a patch version to update the npm readme.

@markhughes
Copy link

Using 2.0.0-canary.20200504.1 resolved the issue on my end.. I don't think we have a choice but to use dev/canary builds at the moment. It looks like 2.0 has been in development for a few years, not sure if there is any news on a stable release?

For those wanting to do this for third party dependencies you can use npm shrinkwrap, and force your other dependencies to use it.

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

9 participants