Zach Lysobey
Zach Lysobey

Reputation: 15724

Can I install Polymer (1.0) with NPM?

I'm trying to use Polymer on a new project, and was trying to avoid using Bower in favor of NPM for front-end dependency management.

The getting started page gives instructions for using Bower (and using a .zip file, etc...) but no mention of NPM.

I have used NPM by pointing directly at a GitHub repo before, but I cannot seem to get this to work for Polymer.

When I run this:

npm install [email protected]:Polymer/polymer.git#v1.0.5

I get this error:

npm ERR! notarget No compatible version found: git@'github.com:Polymer/polymer.git'

npm ERR! notarget Valid install targets:

npm ERR! notarget ["0.1.0","0.1.1","0.1.2","0.1.3","0.1.4","0.1.5"]

Is there something I'm missing, or do I need to bite the bullet and use Bower?

Upvotes: 10

Views: 8502

Answers (4)

synk
synk

Reputation: 199

EDIT 2016/10/25 The Polymer team announced at the Polymer Summit 2016 that they will be looking into supporting npm via yarn.

[sudo] npm install -g yarn yarn add Polymer yarn install --flat

OLD AWNSER

There is currently no way I know of to get polymer running with NPM.

Polymer is meant to work with Bower. All dependencies of a Polymer that are declared in https://github.com/Polymer/polymer/blob/master/bower.json like webcomponentsjs will not be downloaded. Therefor if you don't want to download every dependency manually you should use bower.

Upvotes: 5

Kiara Grouwstra
Kiara Grouwstra

Reputation: 5923

Since the earlier answers, Polymer has now indeed become available on NPM. To install it:

npm i Polymer

Note that it doesn't include the standard elements collection; those can be found here:

npm i npm-polymer-elements

You can then include them in your HTML:

<!-- for custom elements -->
<link rel="import" href="/node_modules/@polymer/polymer/polymer.html"/>
<!-- for standard elements -->
<link rel="import" href="/node_modules/paper-button/paper-button.html"/>
<paper-button>click</paper-button>

Unfortunately loading Polymer through webpack currently doesn't seem possible yet, meaning if your node_modules (or bower_components) folder isn't in a publicly accessible location, you may want to make a Grunt/Gulp task to copy it over for after future updates...

Upvotes: 14

Tiddo
Tiddo

Reputation: 6544

The main problem with Polymer is that the tagged build commits don't have a package.json, making it impossible to install them with npm (e.g. see v1.1.1). This means that in order to install Polymer with npm you'll need some helper tool. Perhaps the best candidate for this is Napa.

Napa is a package for installing git projects that do not have a (valid) package.json. The npm page already explains how to use it, here a quick summary for Polymer:

  1. npm install napa --save-dev
  2. Update your package.json to include this (replace x.y.z with the version you want):

    {
        "scripts" : {
            "install" : "napa"
        },
        "napa" : {
            "polymer" : "polymer/polymer#vX.Y.Z"
        }
    }
    

Note that napa just clones the repo into the node_modules folder, hence no dependencies of polymer will be installed alongside of it, but you can keep all of the configuration in your package.json instead of having to use bower.

Upvotes: 5

yuryja
yuryja

Reputation: 1

Try installing bower method!

"npm install -g bower"

Then type inside your folder:

"bower init"

Follow the instructions, then type:

"bower install --save Polymer/polymer

Create an index.html file and start to work!!!

Upvotes: -13

Related Questions