Ejection fails if package.json omits optionalDependencies key
Created by: bmuenzenmeyer
Desribe the bug
Ejecting an app that does not have an optionalDependencies
key within its package.json
causes a failure.
This seems similar to https://github.com/facebook/create-react-app/issues/2655 and https://github.com/facebook/create-react-app/pull/2657.
Workaround: preserve the optionalDependencies
key in the package.json
of the app or template (in my case, we have a custom react-scripts
)
I have a fix, which I will PR against this shortly.
Environment
$ npx create-react-app --info
Environment Info:
System: OS: Windows 10 CPU: (8) x64 Intel(R) Xeon(R) CPU E3-1505M v5 @ 2.80GHz Binaries: Node: 10.15.3 - C:\Program Files\nodejs\node.EXE Yarn: 1.9.2 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Not Found Internet Explorer: 11.0.14393.2007 npmPackages: react: ^16.8.6 => 16.8.6 react-dom: ^16.8.6 => 16.8.6 npmGlobalPackages:
Steps to reproduce
-
npx create-react-app test-app --scripts-version @bmuenzenmeyer/react-scripts
(though I suppose you could generate the standard template and remove theoptionalDependencies
key just the same) cd test-app
npm run eject
Expected behavior
Ejection should succeed
Actual behavior
$ npm run eject
> test-app@0.1.0 eject C:\src\tmp\test-app
> react-scripts eject
NOTE: Create React App 2+ supports TypeScript, Sass, CSS Modules and more without ejecting: https://reactjs.org/blog/2018/10/01/create-react-app-v2.html
? Are you sure you want to eject? This action is permanent. Yes
Ejecting...
Copying files into C:\src\tmp\test-app
Adding \config\env.js to the project
Adding \config\modules.js to the project
Adding \config\paths.js to the project
Adding \config\pnpTs.js to the project
Adding \config\webpack.config.js to the project
Adding \config\webpackDevServer.config.js to the project
Adding \config\jest\cssTransform.js to the project
Adding \config\jest\fileTransform.js to the project
Adding \scripts\build.js to the project
Adding \scripts\start.js to the project
Adding \scripts\test.js to the project
Updating the dependencies
Removing @bmuenzenmeyer/react-scripts from dependencies
ipts\eject.js:188:42)
at process._tickCallback (internal/process/next_tick.js:68:7)ipts\eject.js:14
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-app@0.1.0 eject: `react-scripts eject`
npm ERR! Exit status 1 property '@babel/core' of undefined
npm ERR! ject.keys.forEach.key (C:\src\tmp\test-app\node_modules\@bmuenzenmeyer\react-scripts\scriptsnpm ERR! Failed at the test-app@0.1.0 eject script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
at inquirer.prompt.then.answer (C:\src\tmp\test-app\node_modules\@bmuenzenmeyer\react-scripts\scrnpm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\<<REDACTED>>\AppData\Roaming\npm-cache\_logs\2019-06-28T17_48_09_083Z-debug.log
Reproducible demo
https://github.com/bmuenzenmeyer/test-app
git clone https://github.com/bmuenzenmeyer/test-app.git
cd test-app
npm install
npm run eject