Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install NPM package from GitHub for Meteor?

Tags:

npm

meteor

I have forked an npm package on GitHub, made changes to it, and now want to install the package in my Meteor app directly from GitHub.

My package.json looks like so:

{
  "dependencies": {    
    "semantic-ui-react": "git+https://[email protected]/nolandg/Semantic-UI-React.git",
  }
}

I then run

meteor npm install

Which appears to work fine and tells me it's installed the package:

[email protected]  (git+https://[email protected]/nolandg/Semantic-UI-React.git#f27d5c736e5de1eed0acf7769f18caee57578526)

And indeed the package appears in the node_modules folder. But when I try to start my Meteor app, I get this error:

Cannot set property '/my-website/node_modules/semantic-ui-react/package.json' of undefined

at Resolver._resolvePkgJsonMain (/tools/isobuild/resolver.js:320:9)

Has anyone successfully install an npm package in a Meteor app directly from GitHub? I can't figure this one out. Thanks!

Meteor version: 1.4.2.3

like image 722
Noland Avatar asked Oct 17 '22 21:10

Noland


1 Answers

The main reason why the package does not work when fetching from git is because it is not configured to work that way. This is not a Meteor specific problem, but a problem that a JS developer may face sometimes.

For this particular case there are two problems:

  • The whitelist files field in package.json only contains src and dist folder. That means when you fetch it by npm almost all config files needed to build the code are gone.
  • Code for this package requies to be built in order to work with your code. This is done when the author publish it to npm, but you fetch it directly from github so this step is undone.

Because you already folked and modified the package, so let modify the package.json as below (remove all the comments I added them to give you some explanation), push it to github, and fetch it again by npm:

// remove the "files" field
// ...
"scripts": {
  // this script is used to build the package
  "postinstall": "postinstall-build dist \"npm run build:commonjs\""
  // ...
},
"dependencies": {
  // this helps build the package
  "postinstall-build": "^2.1.3"
},
// ...
like image 76
kkkkkkk Avatar answered Oct 20 '22 23:10

kkkkkkk