-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
"Unable to resolve module mock-aws-s3" with Expo Router API Routes + bcrypt
#32383
Comments
Potentially relevant background from @EvanBacon on Expo Router API Routes not supporting all Node.js packages:
|
Workaround (use
|
I'm going to close this issue and comment here facebook/metro#1377 |
@marklawlor facebook/metro#1377 is for a slightly different package actually - But if you think I should open a separate issue in Metro for |
As I explained that comment, this is an issue with how |
I think I understand your general sentiment, but these assertions are not entirely true:
Because Expo Router contains Metro configuration, this also is relevant for Expo. |
I understand, thats why I marked my comment in 1377 as off-topic. In regards to this issue, the comment about |
Got it - mostly agreed here. One last nit from my side would be that in the future (once Metro has support for native Node.js addons), the issues I reported with both
|
@karlhorky Your comments are mixing up between For the issue with
Since Metro does not support |
Yeah, sorry about that. I'll try to keep them separated into their separate issues.
Ah interesting, wasn't aware that the modifying Metro config in Maybe useful for us at some point... |
Minimal reproducible example
https://github.com/karlhorky/repro-expo-router-api-routes-bcrypt
Which package manager are you using? (Yarn is recommended)
npm
If the issue is web-related, please select the bundler (
web.bundler
in theapp.json
)metro
Summary
We are trying to use
bcrypt
in Expo Router API Routes and we're running into an errorUnable to resolve module mock-aws-s3
:Adding the dependencies
mock-aws-s3
,aws-sdk
,nock
which are required bynode-pre-gyp
(PR) allows the bundling to succeed but this leads to a further error at runtime, becausenode-pre-gyp
looks forbcrypt
'spackage.json
at runtime:Cause of Error
The
Unable to resolve module mock-aws-s3
and.../package.json does not exist
errors originates frombcrypt
's dependencynode-pre-gyp
, caused bynode-pre-gyp
not supporting bundlers:Recommendation: "externals"
The recommendations in related
bcrypt
discussions is to exclude these modules from the bundle (using a technique often called "externals"):externals
option: Fails in Next.js app/ directory incl. with API Route Handlers kelektiv/node.bcrypt.js#979 (comment)--external:
flag: Problem with bcrypt's 'node-pre-gyp' dependency kelektiv/node.bcrypt.js#964 (comment)Unclear how to add "externals" in Metro
But I can't see how I can modify the Metro configuration for Expo Router API Routes, to add something similar to "externals".
Looking through the Expo source code, I can see this file, which has Metro options, but not sure how to alter them from userland:
expo/packages/@expo/cli/src/start/server/metro/MetroBundlerDevServer.ts
Lines 554 to 577 in 48d64e9
Reproduction
Creation steps:
mkdir repro-expo-router-api-routes-bcrypt && cd repro-expo-router-api-routes-bcrypt
npx create-expo-app@latest .
rm -r ./node_modules && npm install
(forEMFILE
error)app.json
withexpo.web.output = "server"
andexpo.plugins[0][1] = { "origin": "http://localhost:8081" }
app/hash+api.ts
, with an Expo Router API Route, usinghashSync
frombcrypt
app/(tabs)/index.tsx
, add afetch()
of the API Route insideuseFocusEffect
npm start
and observe the error after API Route bundlingEnvironment
The text was updated successfully, but these errors were encountered: