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

Invalid json for config beacuse previous logger.info call #1093

Closed
emanuelb opened this issue Apr 3, 2020 · 5 comments
Closed

Invalid json for config beacuse previous logger.info call #1093

emanuelb opened this issue Apr 3, 2020 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@emanuelb
Copy link

emanuelb commented Apr 3, 2020

Description

My react-native app build failed because of #1090 but the underlying bug is that calling
node ./node_modules/react-native/cli.js config will result in invalid json as it will contain at the beginning the message:
"info React Native CLI will continue to run if your local environment matches what React Native expects. If it does fail, check out"

logger.info(
`React Native CLI will continue to run if your local environment matches what React Native expects. If it does fail, check out "${absolutePath}" and adjust your environment to match it.`,
);

Even after fixing #1090 it still can happen as ulimit call can fail, for example with "Operation not permitted"

Reproducible Demo

# docker build --rm -t react-native-cli-bugs-1090-1093 .
# docker run --rm -it --entrypoint /bin/sh react-native-cli-bugs-1090-1093
FROM alpine:edge
WORKDIR /app/
RUN apk update && apk upgrade && apk add yarn && yarn add react-native
WORKDIR /app/node_modules/react-native/
# bug https://github.com/react-native-community/cli/issues/1090
RUN set -x && \
    node ./cli.js config | head && \
    node ./cli.js config 2>/dev/null | head && \
    apk add bash && \ 
# bug https://github.com/react-native-community/cli/issues/1093
    ulimit -n 50 && \
    node ./cli.js config | head && \
    node ./cli.js config 2>/dev/null | head

Result

+ node ./cli.js config
+ head
warn Failed to run environment setup script "setup_env.sh"

Error: Command failed: /app/node_modules/@react-native-community/cli/setup_env.sh
env: can't execute 'bash': No such file or directory

info React Native CLI will continue to run if your local environment matches what React Native expects. If it does fail, check out "/app/node_modules/@react-native-community/cli/setup_env.sh" and adjust your environment to match it.
{
  "root": "/app/node_modules/react-native",
  "reactNativePath": "/app/node_modules/react-native",
  "dependencies": {},
  "commands": [
    {
      "name": "log-ios",
      "description": "starts iOS device syslog tail"
    },
+ + head
node ./cli.js config
info React Native CLI will continue to run if your local environment matches what React Native expects. If it does fail, check out "/app/node_modules/@react-native-community/cli/setup_env.sh" and adjust your environment to match it.
{
  "root": "/app/node_modules/react-native",
  "reactNativePath": "/app/node_modules/react-native",
  "dependencies": {},
  "commands": [
    {
      "name": "log-ios",
      "description": "starts iOS device syslog tail"
    },
+ ulimit -n 50
+ + head
node ./cli.js config
warn Failed to run environment setup script "setup_env.sh"

Error: Command failed: /app/node_modules/@react-native-community/cli/setup_env.sh
/app/node_modules/@react-native-community/cli/setup_env.sh: line 8: ulimit: open files: cannot modify limit: Operation not permitted

info React Native CLI will continue to run if your local environment matches what React Native expects. If it does fail, check out "/app/node_modules/@react-native-community/cli/setup_env.sh" and adjust your environment to match it.
{
  "root": "/app/node_modules/react-native",
  "reactNativePath": "/app/node_modules/react-native",
  "dependencies": {},
  "commands": [
    {
      "name": "log-ios",
      "description": "starts iOS device syslog tail"
    },
+ head
+ node ./cli.js config
info React Native CLI will continue to run if your local environment matches what React Native expects. If it does fail, check out "/app/node_modules/@react-native-community/cli/setup_env.sh" and adjust your environment to match it.
{
  "root": "/app/node_modules/react-native",
  "reactNativePath": "/app/node_modules/react-native",
  "dependencies": {},
  "commands": [
    {
      "name": "log-ios",
      "description": "starts iOS device syslog tail"
    },
@emanuelb
Copy link
Author

ulimit call will also fail when run under rootless container, such as:
using podman on fedora and run:

podman build --rm -t react-native-cli-bugs-1090-1093 .

Result

+ node ./cli.js config
+ head
warn Failed to run environment setup script "setup_env.sh"

Error: Command failed: /app/node_modules/@react-native-community/cli/setup_env.sh
sh: error setting limit: Operation not permitted

this bug is only blocker that make compiling my react native app in rootless container fail (after changing ulimit call to /bin/true in setup_env.sh it work)

@thymikee
Copy link
Member

We should be safe to move this check:

// when we run `config`, we don't want to output anything to the console. We
// expect it to return valid JSON
if (process.argv.includes('config')) {
logger.disable();
}

up, right after this one:
// Commander is not available yet
logger.setVerbose(process.argv.includes('--verbose'));

Are you open to make a PR? :)

@thymikee thymikee added bug Something isn't working good first issue Good for newcomers and removed bug report labels Apr 23, 2020
@emanuelb
Copy link
Author

Your instructions for a patch looks ok (moving the check will fix the issue).
I prefer that you/someone-else will do the PR (write the commit message & run the project tests to ensure it will not break anything else)

@thymikee
Copy link
Member

@TMaszko is on it :)

@thymikee
Copy link
Member

Closed via #1131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants