callstack / haul

Haul is a command line tool for developing React Native apps, powered by Webpack
MIT License
3.64k stars 194 forks source link

Haul not working with Amazon aws sdk #741

Closed airamrguez closed 4 years ago

airamrguez commented 4 years ago

Hello!

Environment

RN 0.62.2 I'm using haul version 0.22.1 which I have installed today.

$ node_modules/@haul-bundler/cli/bin/cli.js --version
0.22.1

Description

I'm trying to make Haul work with my React Native project and I have an issue with the aws-sdk from Amazon. This sdk has circular references and I think this is the cause of the error in Haul.

Reproducible Demo

In an empty Haul project, just simply try to import Amplify from aws-amplify.

import Amplify from 'aws-amplify';

This is the output that I get:

/Users/myproject/node_modules/@aws-sdk/url-parser-node/build/index.js
Module not found: Error: Recursion in resolving
Stack:
resolve: (/Users/myproject/node_modules/@aws-sdk/url-parser-node/build) url
newResolve: (/Users/myproject/node_modules/@aws-sdk/url-parser-node/build) url
parsedResolve: (/Users/myproject/node_modules/@aws-sdk/url-parser-node/build)
url module
describedResolve:
(/Users/myproject/node_modules/@aws-sdk/url-parser-node/build) url module
resolve: (/Users/myproject/node_modules/@aws-sdk/url-parser-node) url/ module
newResolve: (/Users/myproject/node_modules/@aws-sdk/url-parser-node) url/
module
parsedResolve: (/Users/myproject/node_modules/@aws-sdk/url-parser-node) url
directory module
describedResolve: (/Users/myproject/node_modules/@aws-sdk/url-parser-node) url
directory module
resolve: (/Users/myproject/node_modules/@aws-sdk/url-parser-node) url/
directory module
newResolve: (/Users/myproject/node_modules/@aws-sdk/url-parser-node) url/
directory module
@ /Users/myproject/node_modules/@aws-sdk/url-parser-node/build/index.js
4:14-28
@ /Users/myproject/node_modules/@aws-amplify/storage/lib/providers/AWSS3Provid
erManagedUpload.js
@ /Users/myproject/node_modules/@aws-amplify/storage/lib/providers/AWSS3Provid
er.js
@ /Users/myproject/node_modules/@aws-amplify/storage/lib/providers/index.js
@ /Users/myproject/node_modules/@aws-amplify/storage/lib/index.js
@ /Users/myproject/node_modules/aws-amplify/lib/index.js
@ ./src/App.js
@ ./index.js
@ multi ./index.js

In fact, if you build the same project using Metro bundler you get some warnings like this:

[Tue May 19 2020 19:39:35.508]  WARN     Require cycle: node_modules/@aws-amplify/pubsub/lib-esm/index.js -> node_modules/@aws-amplify/pubsub/lib-esm/PubSub.js -> node_modules/@aws-amplify/pubsub/lib-esm/Providers/index.js -> node_modules/@aws-amplify/pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider.js -> node_modules/@aws-amplify/pubsub/lib-esm/index.js

But in Metro, despite those warnings, it works.

zamotany commented 4 years ago

This is a Webpack issue, not a Haul one. What I can tell though from the error is that @aws-sdk/url-parser-node is trying to use url module which is only available in Node. You could try polyfilling url module. It seems weird that @aws-sdk/url-parser-node is used in the first place.

zamotany commented 4 years ago

You can also try aliasing @aws-sdk/url-parser-node to @aws-sdk/url-parser-browser.

airamrguez commented 4 years ago

@zamotany Thanks for your fast response and guidance!!! I’ll try tomorrow morning 🙂

airamrguez commented 4 years ago

@zamotany aliasing @aws-sdk/url-parser-node to @aws-sdk/url-parser-browser worked! Thanks Again!