create-react-app 无法再脚手架 TypeScript 项目了...

czq61nw1  于 22天前  发布在  React
关注(0)|答案(4)|浏览(14)

当我运行命令:

npx create-react-app cra-example-app --template typescript

它以这个奇怪的消息结尾,并创建了一个似乎无法构建的js项目...

The react-scripts version you're using is not compatible with the --template option.

Installing react, react-dom, and react-scripts...
6yoyoihd

6yoyoihd1#

命令运行正常。根据npx的安装情况,似乎是节点版本问题?
我使用的是Node v14。您能提供更多关于您正在使用的版本的详细信息吗?
此外,项目名称确实不太好。请添加更多具体信息并保持友好 :)

8oomwypt

8oomwypt2#

尝试这个 npx clear-npx-cache

qncylg1j

qncylg1j3#

更新:运行 npm cache clean --force 解决了使用 nxp create-react-app 的问题。
嗯,"npx create-react-app foo --template typescript" 会创建一个包含 package.json、package-lock.json 和 node_modules 的文件夹,仅此而已。我已经尝试了 npx clear-npx-cache,但没有任何改变。使用的是 npm 6.14.16 / node 14.19.0。
package.json 中只有几个属性:

{
  "name": "container",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^18.1.0",
    "react-dom": "^18.1.0",
    "react-scripts": "5.0.1"
  }
}

如果我使用 npm install -g create-react-app 将 create-react-app 全局安装,它似乎可以正常工作。所以这不是 create-react-app 的问题,而是一次糟糕的经历。还有其他什么可能导致这个问题?

pod7payv

pod7payv4#

当我在运行npxyarn create时遇到了类似的问题:

$ npx create-react-app ./client --template typecript             
npx: installed 67 in 19.558s

Creating a new React app in [DIR].

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template-typecript...

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/cra-template-typecript - Not found
npm ERR! 404 
npm ERR! 404  'cra-template-typecript@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

Aborting installation.
npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts cra-template-typecript has failed.

事实上,首先全局安装yarn global add create-react-app,然后直接运行可执行文件-解决了问题。
非常奇怪的行为...

相关问题