【问题标题】:npx create-react-app get errornpx create-react-app 获取错误
【发布时间】:2018-11-05 16:10:43
【问题描述】:

我正在使用:

Windows 10
npm -v 5.8.0
npx -v 9.7.1

运行npx 时,我得到:"The "path" argument must be of type string"

我正在尝试创建一个 React 应用程序。得到这个错误:

λ npx create-react-app myapp
npx: installed 1 in 4.576s

The "path" argument must be of type string
C:\Users\MyUser\AppData\Roaming\npm\node_modules\create-react-app\index.js
C:\Users\MyUser\AppData\Roaming\npm\node_modules\create-react-app\package.json: Unexpected string in JSON at position 52

【问题讨论】:

  • 你能告诉我们你的package.json文件是什么样的吗?
  • 我已经安装了 npm i create-react-app
  • 尝试新版本的 node.js/npm,我在切换到旧的 node.js 版本时遇到了类似的问题。

标签: reactjs npm npx


【解决方案1】:

运行前

npx 创建反应应用程序

你需要在你的机器上全局安装 create-react-app 使用

npm install -g create-react-app

成功后,您可以继续运行 npx 代码,如下所示

npx create-react-app 应用程序名称

【讨论】:

  • 你能解释一下你的答案吗?仅代码的答案通常难以解释。
【解决方案2】:

错误中的这一行很重要:

C:\Users\MyUser\AppData\Roaming\npm\node_modules\create-react-app\package.json: JSON 中第 52 位的意外字符串

这意味着您的package.json 文件格式不正确。

网上有this等工具可以帮助确保package.json的格式正确。

【讨论】:

  • 我已经安装了 npm i create-react-app。我没有对“package.json”做任何改变。哪些trubles可以acure? package.json 下方:
  • { "_from": "create-react-app", "_id": "create-react-app@1.5.2", "_inBundle": false, "_integrity": "sha512- vnYIzsfTaqai2l07P9qtxhsZgHbzirC2omxKmf16wqvpXao9CNCDmpk+BCZRElih7HTn/mpO3soe8DTZV4DsgQ==", "_location": "/create-react-app", "_phantomChildren": {}, "_requested": { "type": "tag", "registry": true, "raw ": "create-react-app", "name": "create-react-app", "escapedName": "create-react-app", "rawSpec": "", "saveSpec": null, "fetchSpec" : "最新" },
  • 好吧,第 52 行],
  • },“文件”:[“index.js”,“createReactApp.js”],“主页”:“github.com/facebookincubator/create-react-app#readme”,“关键字”:[“react”],跨度>
  • 它是非工作模块“create-react-app”吗?还是我犯了一些愚蠢的错误?
【解决方案3】:

已解决。 不存在任何一个 npx。你必须用完整路径调用 npx:

C:\Users\MyUser\AppData\Roaming\npm\npx.cmd create-react-app MyApp

【讨论】:

    猜你喜欢
    • 2021-04-24
    • 2021-03-03
    • 1970-01-01
    • 2022-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    • 1970-01-01
    相关资源
    最近更新 更多