Skip to content

Try Catch Yarn Function Conflicting with Yarn (Java Package)  #1257

Closed
@kathyw268

Description

@kathyw268

If you have Hadoop installed and run create-react-app, the try catch function calls the yarn java package and returns an error:

Error: Could not find or load main class add
yarn add --dev --exact react-scripts failed

The npm fallback function never gets called.

Activity

gaearon

gaearon commented on Dec 12, 2016

@gaearon
Contributor

Wow, thanks for reporting.
I'm curious if:

  • We can somehow reliably tell yarn corresponds to an npm module before calling it
  • Why catch doesn't catch the error.
fson

fson commented on Dec 12, 2016

@fson
Contributor

Wow, that's interesting.

somehow reliably tell yarn corresponds to an npm module before calling it

We currently use Yarn if yarn --version exits successfully. We could also check the output of the command. At least the yarn command from a version of Hadoop I installed to test doesn't even recognize the --version and fails. Or we could also use a more specific command (yarn help add?) but the output of --version is easier to assert.

Why catch doesn't catch the error.

This is weird. On my machine, after uninstalling Yarn and installing Hadoop create-react-app uses npm because yarn --version fails:
screen shot 2016-12-12 at 22 14 01

I think we should check the output of yarn --version and validate that it's a valid semver version greater than or equal to 0.16.1 (the first version that works with CRA). The chances of another executable passing that test should be pretty minimal and this is also similar to the test that react-native CLI uses.

gaearon

gaearon commented on Dec 12, 2016

@gaearon
Contributor

@kathyw268 Can you post the output of create-react-app --version? Thanks!

kathyw268

kathyw268 commented on Dec 12, 2016

@kathyw268
Author

@gaearon create-react-app version: 1.0.1

gaearon

gaearon commented on Dec 12, 2016

@gaearon
Contributor

Could you try updating to 1.0.2 and try with it instead?
I'm curious if changes from #1223 made it better.

npm i -g create-react-app@1.0.2

Sorry for spending your time on this.

kathyw268

kathyw268 commented on Dec 13, 2016

@kathyw268
Author

Success! Thanks for being so responsive. Keep up the good work.

fson

fson commented on Dec 13, 2016

@fson
Contributor

Great! Thanks for the confirmation. I'm glad the recent changes to Yarn detection fixed this issue.

bcardi

bcardi commented on Dec 14, 2016

@bcardi

I am developing on Windows 10, just now installed create-react-app and have also just hit this error. I am using nodejs@6.9.2, npm@4.0.3, and create-react-app@1.0.2. The command "yarn --version" returns the following:

Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

fson

fson commented on Dec 14, 2016

@fson
Contributor

@bcardi How does it fail for you? Can you post the output of the create-react-app command? Thanks!

bcardi

bcardi commented on Dec 17, 2016

@bcardi
C:\temp>create-react-app new-react-app
Creating a new React app in C:\temp\new-react-app.

Installing packages. This might take a couple minutes.
Installing react-scripts...

Error: Could not find or load main class add
module.js:471
    throw err;
    ^

Error: Cannot find module 'C:\temp\new-react-app\node_modules\react-scripts\package.json'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at checkNodeVersion (C:\Users\Bob\AppData\Roaming\nvm\v6.9.2\node_modules\create-react-app\index.js:225:21)
    at C:\Users\Bob\AppData\Roaming\nvm\v6.9.2\node_modules\create-react-app\index.js:179:5
    at ChildProcess.<anonymous> (C:\Users\Bob\AppData\Roaming\nvm\v6.9.2\node_modules\create-react-app\index.js:165:5)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at ChildProcess.cp.emit (C:\Users\Bob\AppData\Roaming\nvm\v6.9.2\node_modules\create-react-app\node_modules\cross-spawn\lib\en
oent.js:40:29)
bcardi

bcardi commented on Dec 17, 2016

@bcardi

FYI, I also have Hadoop installed and its bin folder is in my PATH variable.

C:\>where yarn
C:\apps\hadoop-2.6.0\bin\yarn
C:\apps\hadoop-2.6.0\bin\yarn.cmd

After I removed "C:\apps\hadoop-2.6.0\bin" from my PATH variable, the "create-react-app new-react-app" command completes successfully. This is not ideal as I need to be able to keep Hadoop in my path. We need to find a way for these tools to co-exist.

20 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bcardi@fson@gaearon@kathyw268@batjko

        Issue actions

          Try Catch Yarn Function Conflicting with Yarn (Java Package) · Issue #1257 · facebook/create-react-app