如何在 Laravel Mix 中导入 Github 的 fork npm 包?
在package.json
中,我有:
"vue-search-select": "github:my-github-account/vue-search-select"
然后运行npm install
,没有错误。
在 app.js
中,我尝试导入分叉包:
import { ModelSelect } from 'vue-search-select';
当我运行 npm run watch
时,收到以下消息:
Module not found: Error: Can't resolve 'vue-search-select'
更新:
我比较node_modules
中的原始版本和分叉版本:原始版本包含 dist
文件夹,但分叉版本没有。在github上,原来的也没有这个文件夹。并且 dist
包含在 .gitignore
中。
In package.json
, I have:
"vue-search-select": "github:my-github-account/vue-search-select"
And then run npm install
, no error.
In app.js
, I try to import the forked package:
import { ModelSelect } from 'vue-search-select';
When I run npm run watch
, got the below message:
Module not found: Error: Can't resolve 'vue-search-select'
UPDATE:
I compared the original version and forked version in node_modules
: Original contains dist
folder but forked version don't have. In github, the original one also don't have this folder. And dist
is included in .gitignore
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我了解,对于
package.json< /code> GitHub URL
,从版本 1.1.65 开始,您可以将 GitHub URL 引用为
foo:user/foo-project
,如 见此处。但我仍然建议使用更完整的 URL:
这样,您就可以控制方案(HTTPS 或 SSH)并可以检查使用哪些凭据(HTTPS 的缓存用户名/密码或 SSH 的私钥)。
OP Wilson 在讨论中发表评论 将
dist/
添加到存储库可能是一个选项,如 在这里。可以在package.json中声明
prepare
脚本,例如这个。正如威尔逊的答案中所述
I understand that, for
package.json
GitHub URL, As of version 1.1.65, you can refer to GitHub URLs as justfoo:user/foo-project
, as seen here.But I would still recommend a more complete URL instead:
That way, you control the scheme (HTTPS or SSH) and can check which credentials (cached username/password for HTTPS or private key for SSH) is used.
The OP Wilson comments in the discussion that adding
dist/
to the repo could be an option, as in here.A
prepare
script can be declared in the package.json, such as this one.As noted in Wilson's answer
最后,我找到了解决方案:
添加
"prepare": "npm run lib:build"
(或者其他内容取决于包如何构建,可以在package.json
中查看code>) 到package.json
的scripts
到分叉包。并推送到github。然后,在使用分叉包的项目中,只需在
package.json
中保留"package-name": "github:my-github-account/package-name"
即可并再次运行npm install
。没有其他变化。Finally, I found a solution:
Add
"prepare": "npm run lib:build"
(or something else depends on the package how to build, can check it inpackage.json
) toscripts
ofpackage.json
to the forked package. And push to github.Then, in the project that using the forked package, just keep
"package-name": "github:my-github-account/package-name"
inpackage.json
and runnpm install
again. No other changes.