TooTallNate / node-proxy-agent

Maps proxy protocols to `http.Agent` implementations
285 stars 69 forks source link

v5.0.0 is not compatable with webpack #68

Closed vijaybabu4589 closed 1 year ago

vijaybabu4589 commented 3 years ago

i am using angular-devkit/build-angular (which uses webpack) to build nodejs server, After updating to npm package node-proxy-agent v5.0.0 dist file failed to start.

../node_modules/vm2/lib/main.js:723:104-111 - Warning: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

node ./server/dist-server/main.js

/server/dist-server/main.js:469819
  __webpack_require__(60863),
                      ^^^^^
SyntaxError: Unexpected number
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

i think its because of PR, vm2 has a compatibility issues with webpack https://github.com/patriksimek/vm2/issues/70

is there any work around ?

vijaybabu4589 commented 3 years ago

Work around

use angular-builders/custom-webpack to exclude vm2 from webpack bundling

SamMcFaddenBJSS commented 2 years ago

This is causing some major issues with our deployments and pipelines. We upped to 5.0.0 to avoid the npm high sec vulnerability BUT now we can't compile our lambdas. Any idea if this situation might be getting resolved soon please? Or tangible workarounds. We have tried a number of different options and libraries and approaches but so far no dice. Thanks.

antpingelli commented 2 years ago

+1 to this, we are seeing SyntaxError: Unexpected string on Lambda when upgrading to 5.0.0

TooTallNate commented 2 years ago

Does @vijaybabu4589's workaround work for you?

antpingelli commented 2 years ago

We are not using angular-devkit/build-angular but if I use webpack externals to exclude vm2 I get Error: Cannot find module 'vm2' so I am not sure what angular-builders/custom-webpack is doing to exclude it successfully

vijaybabu4589 commented 2 years ago

@antpingelli try this https://github.com/patriksimek/vm2/issues/70#issuecomment-340221293

antpingelli commented 2 years ago

@antpingelli try this patriksimek/vm2#70 (comment)

This works but feels like a temporary fix rather than a long term solution. We can no longer use the zip plugin from webpack which makes deploying our 10 lambdas more involved. I do not think this is acceptable so we will be looking for other ways around this

@TooTallNate is this not something that can be fixed from your end?

TooTallNate commented 2 years ago

@TooTallNate is this not something that can be fixed from your end?

Not really. It's an issue with the vm2 module. proxy-agent is just a consumer of this module.

spidgorny commented 1 year ago

As a side-effect this leads to

ENOENT: no such file or directory, open '/var/task/contextify.js'

after deploying this to AWS Lambda with serverless.

TooTallNate commented 1 year ago

This code in this repository has been moved to the proxy-agents monorepo, so I am closing this pull request. If you feel that this issue still exists as of the latest release, feel free to open a new issue over there.