"react-scripts" Required For TypeScript, Even When Using "--scripts-version"
Created by: devloco
Is this a bug report?
Yes
Did you try recovering your dependencies?
Yes
Which terms did you search for in User Guide?
I didn't see anything that looked relevant.
Environment
Uh.. I get an exception running that command. But create-react-app itself works fine, creating an app. This exception doesn't seem to be the culprit. I'm happy to try other commands. I'm assuming this exception is a known problem.
- I'm on Windows 10
- Normal Windows cmd prompt
- npx create-react-app --info
- Here's the exception, but like I said, this error isn't the culprit to my actual issue.
` Environment Info: (node:3520) UnhandledPromiseRejectionWarning: Error: The system cannot find the path specified.
at Function.e.exports.sync (C:\Users\baez\AppData\Roaming\npm-cache\_npx\3520\node_modules\create-react-app\node_modules\envinfo\dist\envinfo.js:1:7778)
at Object.copySync (C:\Users\baez\AppData\Roaming\npm-cache\_npx\3520\node_modules\create-react-app\node_modules\envinfo\dist\envinfo.js:1:104976)
at Object.t.writeSync.e [as writeSync] (C:\Users\baez\AppData\Roaming\npm-cache\_npx\3520\node_modules\create-react-app\node_modules\envinfo\dist\envinfo.js:1:123499)
at C:\Users\baez\AppData\Roaming\npm-cache\_npx\3520\node_modules\create-react-app\node_modules\envinfo\dist\envinfo.js:1:124274
at Promise.all.then.e (C:\Users\baez\AppData\Roaming\npm-cache\_npx\3520\node_modules\create-react-app\node_modules\envinfo\dist\envinfo.js:1:124289)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:3520) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:3520) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. `
Steps to Reproduce
Use create-react-app to create a new app, use the --scripts-version arg and the --typescript arg. My own scripts fork is WordPress specific, so you might not be setup to use it. I believe the problem will appear with any --scripts-version arg. But here are my specific steps:
create-react-wptheme my react-scripts fork (branch)
- npx create-react-wptheme foo --typescript
- cd foo/react-src
- npm run start (sets up the initial WP theme files)
- Launch WordPress and select this theme. Be sure to click "view site"
- Back at your command prompt: npm run start
- See TypeScript compile error about "Can not find module ./logo.svg"
- End NPM
- npm install react-scripts
- npm run start
- TypeScript compiles with no errors.
Expected Behavior
Step #6 above should show a successful TypeScript compile.
Actual Behavior
There's a file called "react-app-env.d.ts" inside the src folder when using the --typescript command arg. In there is a single line:
/// <reference types="react-scripts" />
So looks like maybe two possible solutions to the problem:
- Always install original "react-scripts" when --typescript is specified, even if --scripts-version is specified.
- Change the line in "react-app-env.d.ts" to point at the --scripts-version scripts. I personally don't like this option as it makes maintaining a simple fork that much harder.
Reproducible Demo
(Paste the link to an example project and exact instructions to reproduce the issue.)