im using node 14.
i did a basic netlify nodejs function and it works.
but when i include npm i realm, and import realm into the function, im getting react-native module not found.
i realised both cloudflare worker and netlify function uses webpack to compile its function.
Here is the stack of error:
Error: Command failed with exit code 1: npm run build:functions
ModuleNotFoundError: Module not found: Error: Can't resolve 'react-native' in
'/project/node_modules/realm/lib/browser'
at /project/node_modules/webpack/lib/Compilation.js:925:10
at /project/node_modules/webpack/lib/NormalModuleFactory.js:401:22
at /project/node_modules/webpack/lib/NormalModuleFactory.js:130:21
at /project/node_modules/webpack/lib/NormalModuleFactory.js:224:22
at /project/node_modules/neo-async/async.js:2830:7
at /project/node_modules/neo-async/async.js:6877:13
at /project/node_modules/webpack/lib/NormalModuleFactory.js:214:25
at /project/node_modules/enhanced-resolve/lib/Resolver.js:213:14
at /project/node_modules/enhanced-resolve/lib/Resolver.js:285:5
at eval (eval at create (/project/node_modules/tapable/lib/HookCodeFactory.js:33:10),
<anonymous>:15:1)
at /project/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7
at /project/node_modules/enhanced-resolve/lib/Resolver.js:285:5
at eval (eval at create (/project/node_modules/tapable/lib/HookCodeFactory.js:33:10),
<anonymous>:15:1)
at /project/node_modules/enhanced-resolve/lib/Resolver.js:285:5
at eval (eval at create (/project/node_modules/tapable/lib/HookCodeFactory.js:33:10),
<anonymous>:27:1)
at /project/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43
resolve 'react-native' in '/project/node_modules/realm/lib/browser'
Parsed request is a module
using description file: /project/node_modules/realm/package.json (relative path: ./lib/browser)
resolve as module
/project/node_modules/realm/lib/browser/node_modules doesn't exist or is not a directory
/project/node_modules/realm/lib/node_modules doesn't exist or is not a directory
/project/node_modules/realm/node_modules doesn't exist or is not a directory
/project/node_modules/node_modules doesn't exist or is not a directory
/home/james/www/node_modules doesn't exist or is not a directory
/home/james/node_modules doesn't exist or is not a directory
/home/node_modules doesn't exist or is not a directory
/node_modules doesn't exist or is not a directory
looking for modules in /project/node_modules
using description file: /project/package.json (relative path: ./node_modules)
using description file: /project/package.json (relative path: ./node_modules/react-native)
no extension
/project/node_modules/react-native doesn't exist
.wasm
/project/node_modules/react-native.wasm doesn't exist
.mjs
/project/node_modules/react-native.mjs doesn't exist
.js
/project/node_modules/react-native.js doesn't exist
.json
/project/node_modules/react-native.json doesn't exist
.ts
/project/node_modules/react-native.ts doesn't exist
as directory
/project/node_modules/react-native doesn't exist
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! shopnet@1.0.0 build:functions: `netlify-lambda build functions`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the shopnet@1.0.0 build:functions script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/james/.npm/_logs/2021-11-13T06_32_22_233Z-debug.log
> shopnet@1.0.0 build:functions /project
> netlify-lambda build functions
netlify-lambda: Building functions
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! shopnet@1.0.0 dev: `netlify dev`
npm ERR! Exit status 1
example code i use in my handler
import Realm from 'realm';
const realmApp = new Realm.App({
id: REALM_APP_ID,
});
Realm.App.Sync.setLogLevel(realmApp, 'debug');