Home > Back-end >  How to import a forked npm package of Github in Laravel Mix?
How to import a forked npm package of Github in Laravel Mix?

Time:03-22

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.

CodePudding user response:

I understand that, for package.json GitHub URL, As of version 1.1.65, you can refer to GitHub urls as just foo:user/foo-project, as seen here.

But I would still recommend a more complete URL instead:

git ssh://user@hostname:project.git#commit-ish
git ssh://user@hostname/project.git#commit-ish
git http://user@hostname/project/blah.git#commit-ish
git https://user@hostname/project/blah.git#commit-ish

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.

CodePudding user response:

Finally, I found a solution:

Add "prepare": "npm run lib:build" (or something else depends on the package how to build, can check it in package.json) to scripts of package.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" in package.json and run npm install again. No other changes.

  • Related