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

buildBaseUrl() throws an error when location is undefined and not passing baseUrl #934

Closed
zaki-yama opened this issue Jun 7, 2021 · 3 comments · Fixed by #1590
Closed
Assignees
Labels
bug Something isn't working pkg: rest-api-client @kintone/rest-api-client

Comments

@zaki-yama
Copy link
Contributor

zaki-yama commented Jun 7, 2021

This behavior is related to #855, but still occurs even after merging #855.

Target Package

  • @kintone/rest-api-client (all versions)

Environment

  • React Native (We confirmed the behavior with Expo Go)

Current Behavior

  • Create a React Native project with expo-cli
$ npm install --global expo-cli
$ expo init my-project
  • Install the latest @kintone/rest-api-client
$ npm install @kintone/rest-api-client
  • Modify App.tsx to create KintoneRestAPIClient without baseUrl
 import React from 'react';
 import { StyleSheet, Text, View } from 'react-native';

+import { KintoneRestAPIClient } from "@kintone/rest-api-client";
+
 export default function App() {
+  const client = new KintoneRestAPIClient();
+
   return (
     <View style={styles.container}>
       <Text>Open up App.tsx to start working on your app!</Text>
  • Run npm start and open the app with Expo Go (in iPhone or Android phone)

Then an error occurs.

ReferenceError: Can't find variable: location

Expected Behavior

It would be nice if we can see more helpful error message.
(For example, "In this environment, `baseUrl` is required" )

@zaki-yama zaki-yama added bug Something isn't working pkg: rest-api-client @kintone/rest-api-client labels Jun 7, 2021
@tasshi-me tasshi-me self-assigned this Jun 23, 2022
@tasshi-me
Copy link
Member

Cause

The metro (a bundler for React Native) refers to the main field of package.json and injects browser platform dependencies.
Then, React Native environment throws an error because it doesn't have a location object.

Server log
Started Metro Bundler
iOS Bundling complete 7559ms
iOS Running app on iPhone (4)

ReferenceError: Can't find variable: location

This error is located at:
    in App (created by ExpoRoot)
    in ExpoRoot
    in RCTView (created by View)
    in View (created by AppContainer)
    in DevAppContainer (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in main(RootComponent)
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:95:4 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141:19 in handleException
at node_modules/react-native/Libraries/Core/ReactFiberErrorDialog.js:52:4 in showErrorDialog
at node_modules/react-native/Libraries/ReactNative/renderApplication.js:76:4 in renderApplication
at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:119:25 in runnables.appKey.run
at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:213:4 in runApplication

ReferenceError: Can't find variable: location

This error is located at:
    in App (created by ExpoRoot)
    in ExpoRoot
    in RCTView (created by View)
    in View (created by AppContainer)
    in DevAppContainer (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in main(RootComponent)
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:95:4 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0

Proposal

Add the react-native field to package.json and create React Native dependencies.
By default, metro refers react-native field before the browser and main fields.
https://facebook.github.io/metro/docs/configuration/#resolvermainfields

NOTE: metro does not yet support the exports field.
cf. facebook/metro#670 (comment)

@tasshi-me
Copy link
Member

When debugging with the local @kintone/rest-api-client, we have to copy the built package to my-project/node_modules.
It's because metro does not support yarn link(facebook/metro#68 and facebook/metro#1).

cp -rf path/to/js-sdk/packages/rest-api-client/ path/to/my-project/node_modules/@kintone/rest-api-client/

@tasshi-me
Copy link
Member

We don't support React Native environment but can throw a more helpful error message if location is not defined on browser environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg: rest-api-client @kintone/rest-api-client
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants