【问题标题】:Module Not Found from git url dependency从 git url 依赖项中找不到模块
【发布时间】:2018-11-10 02:30:16
【问题描述】:

我已经派生了 react-flexbox-grid 以添加对隐藏列的支持(这是我第一次贡献),但我无法将包包含在我的项目中。

根据Docs: Git Urls as Dependencies,我将以下内容放入我的 package.json 中:

    "react-flexbox-grid": "falieson/react-flexbox-grid#hidden-columns",

运行 npm i 后,我看到 npm 已获取并且安装包没有错误。

├── react-dom@15.4.1 ├── react-flexbox-grid@0.10.2 (git://github.com/falieson/react-flexbox-grid.git#f8e9e9053430b619f4c7fd79b90ccd4f44d6a05c) ├── react-fontawesome@1.5.0

但是当我启动服务器meteor:webpack抱怨:

./imports/ui/Home/index.jsx 中的错误 找不到模块:错误:无法解析 /Users/falieson/Code/planetx-boilerplate/imports/ui/Home 中的模块“react-flexbox-grid”

我没有更改 index.jsx 上的任何内容

import {Grid, Row, Col} from 'react-flexbox-grid';

这是我的meteor webpack config

{
 "css": {
   "module": true
 },
 "module": {
   "loaders": [
     {
       "test": "/\\.css$/",
       "loader": "style!css?modules",
       "include": "/flexboxgrid/"
     }
   ]
 }
}

【问题讨论】:

  • 你能分享你的 webpack 配置吗?
  • 添加了 webpack 配置,不用担心这个 webpacker 现在是遗留的。我在工作环境中遇到了同样的错误,仍在使用 webpack 1.x,尚未升级到 2.x

标签: node.js meteor webpack open-source


【解决方案1】:

问题是这个 repo 需要构建,package.json 引用了 ./lib/index.js 文件,但它不存在于 repo 中(仅 src 文件夹)。

您可以使用以下方法在本地构建它:

npm run compile

并强制添加 ./lib 文件夹并将其推送到您的 git 存储库。

【讨论】:

    【解决方案2】:
    1. 确保已编译的文件在提交中。
    2. 确保 git ignore 已更新,不会忽略您编译的文件。
    3. npm rm -rf ./node_modules/xxxx 如果模块已安装
    4. npm install --save-dev https://gitlab.com/m_farhan/xxxxx.git#master
    5. 确保在将代码推送到 repo 之前构建代码。
    6. npm xxxxx 更新您的项目。

    【讨论】:

      【解决方案3】:

      不应该是这样吗:

      "react-flexbox-grid": "falieson/react-flexbox-grid#hidden-columns",
      

      package.json 中没有git

      通常我会说它可能是一个私有模块,您可以安装它,因为您有权执行此操作,但在其他环境中无法访问它,因为如果您没有权限,GitHub 会为私有存储库提供 404访问它们。或者你可能没有一个名为“hidden-columns”的分支或碎布,但这里似乎你有那个分支并且模块是公共的,所以这不是问题。

      【讨论】: