Search code examples
laravelgithubnpmlaravel-mixgit-fork

How to import a forked npm package of Github in Laravel Mix?


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.


Solution

  • 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.

    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.

      "scripts": {
        "build": "tsc",
        "prepare": "npm run build"
      },
    

    As noted in Wilson's answer

    the important thing is that the prepare script is added in forked package, not in the project that using the package.