Create-react-app: Try Catch Yarn Function Conflicting with Yarn (Java Package)

Created on 12 Dec 2016  路  16Comments  路  Source: facebook/create-react-app

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.

bug

Most helpful comment

Yarn is also available through the yarnpkg command (https://github.com/yarnpkg/yarn/commit/cefa9a368dd3df1a1f1ecd9e50de9c5fabefbc92). I wonder if we should simply make the installation use the yarnpkg alias instead of yarn. It seems that this would be more reliable, and also allow people who have Hadoop installed use Create React App with Yarn.

All 16 comments

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.

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.

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

@gaearon create-react-app version: 1.0.1

Could you try updating to 1.0.2 and try with it instead?
I'm curious if changes from https://github.com/facebookincubator/create-react-app/pull/1223 made it better.

npm i -g [email protected]

Sorry for spending your time on this.

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

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

I am developing on Windows 10, just now installed create-react-app and have also just hit this error. I am using [email protected], [email protected], and [email protected]. 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.

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

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)

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.

Yarn is also available through the yarnpkg command (https://github.com/yarnpkg/yarn/commit/cefa9a368dd3df1a1f1ecd9e50de9c5fabefbc92). I wonder if we should simply make the installation use the yarnpkg alias instead of yarn. It seems that this would be more reliable, and also allow people who have Hadoop installed use Create React App with Yarn.

Is yarnpkg going to be supported long-term or just a legacy thing, kept around for backward compatibility?

This should be fixed now.
Please update the global command:

npm install -g [email protected]

This will fix the issue in newly created projects.

Closing as fixed.

Hi,

I have one issue, kindly help me

RanjeetS:newlme ranjeet$ npm start

[email protected] start /Library/WebServer/Documents/newlme
react-scripts start

module.js:557
throw err;
^

Error: Cannot find module '../scripts/start'
at Function.Module._resolveFilename (module.js:555:15)
at Function.resolve (internal/module.js:18:19)
at Object. (/Library/WebServer/Documents/newlme/node_modules/.bin/react-scripts:28:25)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:193:16)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: react-scripts start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start 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! /Users/ranjeet/.npm/_logs/2018-02-20T19_45_01_444Z-debug.log

create-react-app version -1.5.2
npm -v 5.6.0

and when I installed npm create-react-app on that time yarn install automatic

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DaveLindberg picture DaveLindberg  路  3Comments

stopachka picture stopachka  路  3Comments

barcher picture barcher  路  3Comments

Aranir picture Aranir  路  3Comments

adrice727 picture adrice727  路  3Comments