【问题标题】:the src and public folder are not creating while using create react app使用 create react app 时未创建 src 和 public 文件夹
【发布时间】:2020-01-21 05:34:01
【问题描述】:

我之前在全球范围内使用并安装了 create react app,但是当我尝试创建一个新应用时它不起作用。

所以我关注了这个:https://github.com/facebook/create-react-app/issues/8097 没用。

然后我尝试了这个:Issues with uninstalling create-react-app 我得到了和那个问题一样的错误。

我也试过了:https://github.com/facebook/create-react-app/issues/8088

https://icetutor.com/question/template-not-provided-using-create-react-app/ 我真的不知道是什么问题。 当我使用命令时

     where create-react-app

我明白了:

    C:\Users\PC 2\AppData\Local\Yarn\bin\create-react-app
    C:\Users\PC 2\AppData\Local\Yarn\bin\create-react-app.cmd

当我使用这个时:

    npm rm -rf C:\Users\Weboffice PC 2\AppData\Local\Yarn\bin\create-react-app

给这个

    npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\package.json'
    npm WARN saveError EPERM: operation not permitted, open 'C:\Users\package-lock.json.1678493388'
    npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\package.json'
    npm WARN Users No description
    npm WARN Users No repository field.
    npm WARN Users No README data
    npm WARN Users No license field.

    up to date in 0.058s

当我使用 yarn 安装时,我得到了

   C:\Users\Weboffice PC 2\React>yarn create react-app test
   yarn create v1.16.0
   [1/4] Resolving packages...
   [2/4] Fetching packages...
   [3/4] Linking dependencies...
   [4/4] Building fresh packages...
   success Installed "create-react-app@3.3.0" with binaries:
   - create-react-app

[############################################# ################################################# ################################################# #######################################] 225/225'

    C:\Users\Weboffice' is not recognized as an internal or external command,
    operable program or batch file.
    error Command failed.
    Exit code: 1
    Command: C:\Users\Weboffice PC 2\AppData\Local\Yarn\bin\create-react-app
    Arguments: test
    Directory: C:\Users\Weboffice PC 2\React
    Output:

    info Visit https://yarnpkg.com/en/docs/cli/create for documentation about 
    this command.

当我使用 yarn 卸载时,我得到了

    C:\Users\Weboffice PC 2\React>yarn uninstall create-react-app
    yarn run v1.16.0
    error Couldn't find a package.json file in "C:\\Users\\Weboffice PC 
    2\\React"
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about 
    this command

问题已更新。

【问题讨论】:

  • 您是否尝试过卸载全球版本的 CRA 并使用“yarn create react-app myapp”(建议使用 yarn,因为您似乎正在使用它)。更多细节在这里:create-react-app.dev/docs/getting-started 另外请分享运行命令时发生的情况和结果的更多细节(显示生成的应用程序的文件夹结构等)。
  • 我已经使用纱线编辑了带有输出的问题,使用它时没有创建文件夹。
  • 要卸载全局包(你显示试图卸载本地),运行“yarn global remove create-react-app”
  • 我也很好奇你的用户名“Weboffice PC 2”,因为它里面有空格(通常不鼓励)。我是 Mac 用户,但有些谷歌搜索导致我来到这里:support.microsoft.com/en-us/help/2454362/… - 错误似乎与您的用户名有关。你最近换了吗?错误:“...Weboffice 无法识别...”
  • @JBallin 不,我没有更改名称。但是您的建议有效。 [1/2] 删除模块 create-react-app... [2/2] 重新生成锁文件并安装缺少的依赖项...成功卸载包。在 3.40 秒内完成。 C:\Users\Weboffice PC 2\React>where create-react-app INFO: 找不到给定模式的文件。

标签: javascript reactjs


【解决方案1】:

错误表明您的用户名中的空格存在问题(这是 npx 的一个已知问题,正在慢慢修复worked on)。

与此同时,这里有一个workaround

我可以通过在我的用户文件夹中创建一个没有空间的目录连接来解决此问题。您可以在管理 powershell 中运行这样的命令:

cmd /c mklink /J C:\Users\myname" "C:\Users\My Name"

然后您可以像使用您的真实用户目录一样使用此联结:

npm config set cache C:\Users\myname\AppData\Roaming\npm-cache

npm config set prefix C:\Users\myname\AppData\Roaming\npm

(以上内容应该更新您的用户 .npmrc 文件)

【讨论】:

    猜你喜欢
    • 2020-04-03
    • 2021-02-12
    • 2020-12-26
    • 1970-01-01
    • 2020-06-13
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 2018-11-16
    相关资源
    最近更新 更多